2019-02-04 01:08:18 +00:00
|
|
|
%, copy_term(X,Y), writeln('....'), writeln(X), writeln(Y).
|
|
|
|
|
2019-02-08 09:33:07 +00:00
|
|
|
:- use_module(library(terms)).
|
|
|
|
|
|
|
|
:- initialization(main).
|
2019-02-04 01:08:18 +00:00
|
|
|
|
2019-02-06 00:08:15 +00:00
|
|
|
:- op(700, xfx, :=: ).
|
|
|
|
|
2019-02-08 09:33:07 +00:00
|
|
|
X :=: X.
|
2019-02-06 00:08:15 +00:00
|
|
|
|
2019-02-04 01:08:18 +00:00
|
|
|
main :-
|
2019-02-08 09:33:07 +00:00
|
|
|
exec.
|
2019-02-04 01:08:18 +00:00
|
|
|
|
2019-02-08 09:33:07 +00:00
|
|
|
test( cyclic_term(X), [X]).
|
|
|
|
test( ground(X), [X]).
|
|
|
|
test( (variables_in_term(X, O), writeln(X=O) ), [X, [], O]).
|
|
|
|
test( (new_variables_in_term(L,X, O), writeln(X+L=O) ), [X, L, O]).
|
|
|
|
test( (variables_within_term(L,X, O), writeln(X+L=O) ), [X, L, O]).
|
|
|
|
test( writeln(X), [X]).
|
|
|
|
test((rational_term_to_tree(X,A,B,[]),
|
|
|
|
writeln((A->B))), [X, A, B]).
|
|
|
|
test(( numbervars(A+B,1,_)), [A, B]).
|
|
|
|
test((rational_term_to_tree(X,A,B,[]), numbervars(A+B,1,_),
|
|
|
|
writeln((A->B))), [X,A,B]).
|
2019-02-05 10:31:17 +00:00
|
|
|
|
2019-02-08 09:33:07 +00:00
|
|
|
:- dynamic i/1.
|
|
|
|
i(0).
|
2019-02-05 10:31:17 +00:00
|
|
|
|
2019-02-08 09:33:07 +00:00
|
|
|
id(I) :-
|
|
|
|
retract(i(I)),
|
|
|
|
I1 is I+1,
|
|
|
|
assert(i(I1)).
|
2019-02-04 01:08:18 +00:00
|
|
|
|
2019-02-08 09:33:07 +00:00
|
|
|
exec :-
|
|
|
|
test( G, [X|Ps] ),
|
|
|
|
functors(G, Fs),
|
|
|
|
format('**** ~w:~n',[Fs]),
|
|
|
|
d(X, GX),
|
|
|
|
id(I),
|
|
|
|
m(I, GX, G, [X|Ps]),
|
|
|
|
fail.
|
|
|
|
exec.
|
2019-02-04 01:08:18 +00:00
|
|
|
|
2019-02-08 09:33:07 +00:00
|
|
|
functors((X,Y),(GX -> GY)) :-
|
|
|
|
!,
|
|
|
|
functors(X, GX),
|
|
|
|
functors(Y, GY).
|
|
|
|
functors(X, GX) :-
|
|
|
|
functor(X, GX, _).
|
2019-02-04 01:08:18 +00:00
|
|
|
|
2019-02-08 09:33:07 +00:00
|
|
|
m( I, GX, G, Ps ) :-
|
|
|
|
%trace,
|
|
|
|
GX,
|
|
|
|
G,
|
|
|
|
!,
|
|
|
|
format( '~d. ~w: ~a.~n', [I, G,yes]).
|
|
|
|
m( I, GX, G, _Ps ) :-
|
|
|
|
GX,
|
|
|
|
format( '~d. ~w: ~a.~n',[I,G,no]).
|
2019-02-05 10:31:17 +00:00
|
|
|
|
2019-02-08 09:33:07 +00:00
|
|
|
d(X, X = [_A] ).
|
|
|
|
d(X, ( X = [a,_A]) ).
|
|
|
|
d(X, ( X = [X]) ).
|
|
|
|
d(X, ( X = [_|X]) ).
|
|
|
|
d(X, ( X = [_,X]) ).
|
|
|
|
d(X, ( X = [_,x]) ).
|
|
|
|
d(X, ( X = [_,x(X)]) ).
|
|
|
|
d(X, ( X= f(X)) ).
|
|
|
|
d(X, ( X= f(X,X)) ).
|
|
|
|
d(X, ( X= f(_,X)) ).
|
|
|
|
d(X, ( X= f(A,A,X)) ).
|
|
|
|
d(X, ( X= f(A,A,g(A))) ).
|
|
|
|
d(X, ( X= f(A,g(X,[A|A]),X)) ).
|
|
|
|
d(X, ( X= f(X,[X,X])) ).
|
|
|
|
d(X, ( X= f(X,[X,g(X)])) ).
|
|
|
|
d(X, ( X= f(_,X/[X])) ).
|
|
|
|
d(X, ( X= f(_,A/[A]), A= f(X,[X,g(X)])) ).
|
|
|
|
d(X, ( X= f(_,A/[A]), A= f(X,[A,g(X)])) ).
|
|
|
|
d(X, ( X= f(_,A/[A]), A= f(B,[X,g(A)]), B=[C|B], C=[X]) ).
|
2019-02-06 00:08:15 +00:00
|
|
|
|
2019-02-08 09:33:07 +00:00
|
|
|
e(X,Y, ( X = t(_A,B,_C,D), Y = [B,E]) ).
|
|
|
|
e(X,Y, ( X = t(_A,_B,_C,_D), Y = [_,_E]) ).
|
|
|
|
e(X,Y, ( X = t(A,_B,C,_D), Y = [ A,C]) ).
|
|
|
|
e(X,Y, ( X = t(A,[X,_D]), Y = [A,_C,_E]) ).
|
|
|
|
e(X,Y, ( X = t(A,[X,C]), Y = [A,C,_E]) ).
|
|
|
|
e(X,Y, ( X = t(A,X,_B,[X,C,_D]), Y = [A,C,_E]) ).
|