Just noticed that SICStus Prolog says that their mode declaration
is a dummy declaration, does nothing. Now I tried whether I can
force SWI Prolog to accept different manually compiled clauses:
test1(X,Y) :- Y = j(C,D), g(C) = A, h(D) = B, f(A,B) = X.
test2(X,Y) :- X = f(A,B), A = g(C), B = h(D), j(C,D) = Y.
Difficult to archive in SWI-Prolog, since it orders unification
on its own, test1/2 and test2/2 will behave the same, since they
are essentially the same:
/* SWI-Prolog 9.3.19 */
?- listing(test1/2), listing(test2/2).
test1(f(A, B), j(C, D)) :-
A=g(C),
B=h(D).
test2(f(A, B), j(C, D)) :-
A=g(C),
B=h(D).
But maybe not necessary since SWI-Prolog has an advanced
instruction set and advanced Prolog logical variable representation?
Would need more testing but the present example is immune:
/* SWI-Prolog 9.3.19 */
?- X = f(g(1),h(2)), time((between(1,1000000,_), test1(X, Y), fail; true)).
% 1,999,998 inferences, 0.094 CPU in 0.100 seconds (93% CPU, 21333312 Lips)
?- X = f(g(1),h(2)), time((between(1,1000000,_), test2(X, Y), fail; true)).
% 1,999,998 inferences, 0.094 CPU in 0.100 seconds (93% CPU, 21333312 Lips)
?- Y = j(1,2), time((between(1,1000000,_), test1(X, Y), fail; true)).
% 1,999,998 inferences, 0.109 CPU in 0.100 seconds (109% CPU, 18285696 Lips)
?- Y = j(1,2), time((between(1,1000000,_), test2(X, Y), fail; true)).
% 1,999,998 inferences, 0.094 CPU in 0.102 seconds (92% CPU, 21333312 Lips)
Not all Prolog systems are that lucky:
/* Scryer Prolog 0.9.4-286 */
?- X = f(g(1),h(2)), time((between(1,1000000,_), test1(X, Y), fail; true)).
% CPU time: 1.163s, 11_000_108 inferences
?- X = f(g(1),h(2)), time((between(1,1000000,_), test2(X, Y), fail; true)).
% CPU time: 1.248s, 11_000_131 inferences
?- Y = j(1,2), time((between(1,1000000,_), test1(X, Y), fail; true)).
% CPU time: 0.979s, 11_000_131 inferences
?- Y = j(1,2), time((between(1,1000000,_), test2(X, Y), fail; true)).
% CPU time: 1.338s, 11_000_131 inferences