1

Constraint Handling Rulesを使用して、SWI-Prologに簡単な制約条件を記述しました。私はmeans([3,is,equal,to,4],[3,equals,4])trueことが期待が、それは代わりに、無限再帰を引き起こしているようだ制約処理ルールによる無限再帰の回避

%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). 

:それは推論の2つの比較的簡単なルールを使用しています

:- 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]). 

私はこのプログラムにsimpagationルールを追加しましたが、それまだ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文献をお読みください。期待どおり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(A,B) \ means(A,B) <=> true.

サンプルクエリ結果:

 
?- 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

この質問を更新しました。このプログラムの修正版を示しています。これは、「ローカルスタック外」エラーを生成します。 –