Constraint Handling Rulesを使用して、SWI-Prolog で簡単な一連の制約を作成しました。2 つの比較的単純な推論規則を使用します。
%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([3,is,equal,to,4],[3,equals,4])
ましたがtrue
、代わりに無限再帰が発生するようです:
:- 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]).
無限再帰を生成しないように推論規則を書き直すことは可能ですか?