私は現在、一連のプロダクションが与えられた後に CYK 解析テーブルを生成する Prolog プログラムに取り組んでいます。ただし、2 つの行をチェックしてそれらが等しいかどうかを確認するのに問題があります。これが私がこれまでに持っているものです:
answer(X,X).
%Checks to see if it is equivalent
equal(X,Y) :- sort(X,X1), sort(Y,Y1), X1 == Y1.
%find the length of the lists
total_length([],0).
total_length([_|Xs],L) :- total_length(Xs,M), L is M+1.
%storing length of lists and possible use of a decrement here to decrement the length...but don't understand how
storing(M,N) :- total_length(L,L_length), total_length(N,N_length), L_length is N_length, answer(L_length,N_length).
%Check for row equivalence...again, trying to find a way to decrement for the recursion, but unsure how to do it
sublist_check(Ra,Rb) :- storing(Ra,Rb), nth0(X,Ra,R1), nth0(Y,Rb,R2), equal(R1,R2), sublist_check(Ra,Rb).
入力が次のようであるとしましょう:
sublist_check([["A"],[],[]], [[],["A"],[]]). -->
false.
sublist_check([["A"],["B","C"],["B","C"]],[["A"],["C","B"],["C","B"]]). -->
true.
私の問題は、リストの最大長に相当する変数を作成し、毎回デクリメントする方法を見つける必要があることだと思いますが、sublist_check の初期長を元の数に戻すというエラーが発生します。
どんな入力/フィードバックでも素晴らしいでしょう、どうもありがとう!