1

Constraint Handling Rules을 사용하여 SWI-Prolog에 간단한 제약 조건 세트를 작성했습니다. 그것은 추론이 상대적으로 간단한 규칙을 사용제약 조건 처리 규칙을 사용하여 무한 재귀 방지

%If A means B, then B means A. 
means(A,B) ==> means(B,A).  
%If A means B and A means C, then B means C. 
means(A,B),means(A,C) ==> means(B,C). 

내가 true을 할 means([3,is,equal,to,4],[3,equals,4]) 예상을하지만, 대신에 무한 재귀가 발생할 것으로 보인다 :이 프로그램에 simpagation 규칙을 추가했지만

:- use_module(library(chr)). 
:- chr_constraint means/2. 
:- initialization(main). 


means([A,equals,B],[A,'=',B]). 
means([A,is,equal,to,B],[A,'=',B]). 
means([A,equals,B],[A,and,B,are,equal]). 


%These are the rules of inference for this program. 
    %If A means B, then B means A. 
    means(A,B) ==> means(B,A).  
    %If A means B and A means C, then B means C. 
    means(A,B),means(A,C) ==> means(B,C). 

main :- 
    %This part works as expected. X = [3,'=',4]. 
    means([3,is,equal,to,4],X),writeln(X), 

    %This statement should be true, so why does it produce an infinite recursion? 
    means([3,is,equal,to,4],[3,and,4,are,equal]). 

그 여전히 Out of local stack 오류에 이르게 : 추론의 규칙을 다시 작성하는

:- use_module(library(chr)). 
:- chr_constraint means/2. 
:- initialization(main). 


%These are the rules of inference for this program. 
    %If A means B, then B means A. 
    means(A,B) ==> means(B,A).  
    %If A means B and A means C, then B means C. 
    means(A,B),means(A,C) ==> means(B,C). 
    means(A,B) \ means(A,B) <=> true. 
    means(A,A) <=> true. 

means([A,equals,B],[A,'=',B]). 
means([A,is,equal,to,B],[A,'=',B]). 
means([A,equals,B],[A,and,B,are,equal]). 

main :- 
    %This part works as expected. X = [3,'=',4]. 
    means([3,is,equal,to,4],X),writeln(X), 

    %This statement should be true, so why does it produce an infinite recursion? 
    means([3,is,equal,to,4],[3,and,4,are,equal]). 

이 가능하도록 그들이 무한 재귀를 생성하지 않습니까?

답변

3

  CHR의 이러한 측면에 대한 자세한 내용은 사용 가능한 CHR 자료를 읽으십시오.

means(A,B) \ means(A,B) <=> true.

샘플 쿼리 : 당신이 CHR의 simpagation 규칙을 추가 할 경우 예를 기대 작품으로, 따라서

  1. Set Semantics

The CHR system allows the presence of identical constraints, i.e. multiple constraints with the same functor, arity and arguments. For most constraint solvers, this is not desirable: it affects efficiency and possibly termination. Hence appropriate simpagation rules should be added of the form: constraint \ constraint <=> true

: 프로그래밍 힌트에 예를 들어

Tips for CHR programming는 포함 결과 :

 
?- means([3,is,equal,to,4],[3,and,4,are,equal]). 
means([3, and, 4, are, equal], [3, is, equal, to, 4]), 
means([3, is, equal, to, 4], [3, and, 4, are, equal]). 
+0

이 simpagation 규칙을 추가했지만 예제가 여전히 SWI-Prolog에서 예상대로 작동하지 않습니다. –

+0

명확한 형식의 간단한 자체 테스트 케이스를 생성하십시오 : (1) ** 프로그램 **, (2) ** 쿼리 **, (3) ** 실제 ** 결과 및 (4) ** 예상 ** 결과. – mat

+0

'로컬 스택 밖'오류를 생성하는이 프로그램의 수정 된 버전을 보여주는이 질문을 업데이트했습니다. –