Prolog "cyclic"
/**
* Warranty & Liability
* To the extent permitted by applicable law and unless explicitly
* otherwise agreed upon, XLOG Technologies AG makes no warranties
* regarding the provided information. XLOG Technologies AG assumes
* no liability that any problems might be solved with the information
* provided by XLOG Technologies AG.
*
* Rights & License
* All industrial property rights regarding the information - copyright
* and patent rights in particular - are the sole property of XLOG
* Technologies AG. If the company was not the originator of some
* excerpts, XLOG Technologies AG has at least obtained the right to
* reproduce, change and translate the information.
*
* Reproduction is restricted to the whole unaltered document. Reproduction
* of the information is only allowed for non-commercial uses. Selling,
* giving away or letting of the execution of the library is prohibited.
* The library can be distributed as part of your applications and libraries
* for execution provided this comment remains unchanged.
*
* Restrictions
* Only to be distributed with programs that add significant and primary
* functionality to the library. Not to be distributed with additional
* software intended to replace any components of the library.
*
* Trademarks
* Jekejeke is a registered trademark of XLOG Technologies AG.
*/
:- multifile(runner_case/5).
:- discontiguous(runner_case/5).
:- multifile(runner_pred/5).
:- discontiguous(runner_pred/5).
:- multifile(runner_file/3).
runner_file(extend, cyclic, 'XLOG 5.2 cyclic').
/****************************************************************/
/* term.p extras */
/****************************************************************/
/* unify_with_occurs_check(X, Y) */
runner_pred(unify_with_occurs_check, 2, extend, cyclic, 'ISO 8.2.2.4').
runner_case(unify_with_occurs_check, 2, extend, cyclic, 'ISO 8.2.2.4, ISO 1') :-
unify_with_occurs_check(1, 1).
runner_case(unify_with_occurs_check, 2, extend, cyclic, 'ISO 8.2.2.4, ISO 2') :-
unify_with_occurs_check(X, 1),
X == 1.
runner_case(unify_with_occurs_check, 2, extend, cyclic, 'ISO 8.2.2.4, ISO 3') :-
unify_with_occurs_check(X, Y),
X == Y.
runner_case(unify_with_occurs_check, 2, extend, cyclic, 'ISO 8.2.2.4, ISO 4') :-
unify_with_occurs_check(_, _).
runner_case(unify_with_occurs_check, 2, extend, cyclic, 'ISO 8.2.2.4, ISO 6') :-
unify_with_occurs_check(f(X,def), f(def,Y)),
X == def, Y == def.
runner_case(unify_with_occurs_check, 2, extend, cyclic, 'ISO 8.2.2.4, ISO 8') :-
\+ unify_with_occurs_check(1, 1.0).
runner_case(unify_with_occurs_check, 2, extend, cyclic, 'ISO 8.2.2.4, ISO 10') :-
\+ unify_with_occurs_check(f(X, 1), f(a(X))).
runner_case(unify_with_occurs_check, 2, extend, cyclic, 'ISO 8.2.2.4, ISO 11') :-
\+ unify_with_occurs_check(f(X, Y, X), f(a(X), a(Y), Y, 2)).
runner_case(unify_with_occurs_check, 2, extend, cyclic, 'ISO 8.2.2.4, ISO 13') :-
\+ unify_with_occurs_check(f(X, 1), f(a(X), 1)).
runner_case(unify_with_occurs_check, 2, extend, cyclic, 'ISO 8.2.2.4, ISO 16') :-
\+ unify_with_occurs_check(f(X, Y, X, 1), f(a(X), a(Y), Y, 2)).
runner_case(unify_with_occurs_check, 2, extend, cyclic, 'ISO 8.2.2.4, XLOG 1') :-
X = f(X,_), unify_with_occurs_check(X, _).
runner_case(unify_with_occurs_check, 2, extend, cyclic, 'ISO 8.2.2.4, XLOG 2') :-
X = f(X,A), \+ unify_with_occurs_check(X, A).
/* occurs_check(X, Y) */
runner_pred(occurs_check, 2, extend, cyclic, 'ISO 7.3.3').
runner_case(occurs_check, 2, extend, cyclic, 'ISO 7.3.3, ISO 1') :-
occurs_check(X, f(_,X,_)).
runner_case(occurs_check, 2, extend, cyclic, 'ISO 7.3.3, ISO 2') :-
\+ occurs_check(_, f(_,_,_)).
/* acyclic_term(X) */
runner_pred(acyclic_term, 1, extend, cyclic, 'Corr.2 8.3.11.4').
runner_case(acyclic_term, 1, extend, cyclic, 'Corr.2 8.3.11.4, ISO 1') :-
acyclic_term(a(_,1)).
runner_case(acyclic_term, 1, extend, cyclic, 'Corr.2 8.3.11.4, ISO 2') :-
X = f(X), \+ acyclic_term(X).
runner_case(acyclic_term, 1, extend, cyclic, 'Corr.2 8.3.11.4, XLOG 1') :-
X = f(X), Y = g(X), \+ acyclic_term(Y).
runner_case(acyclic_term, 1, extend, cyclic, 'Corr.2 8.3.11.4, XLOG 2') :-
X = f(Y), Y = g(X), Z = h(X), \+ acyclic_term(Z).
runner_case(acyclic_term, 1, extend, cyclic, 'Corr.2 8.3.11.4, XLOG 3') :-
X = [a,b,Y|c], Y = [d,e,Z|f], Z = [g,h,i], acyclic_term(X).
runner_case(acyclic_term, 1, extend, cyclic, 'Corr.2 8.3.11.4, XLOG 4') :-
X = [a,b,Y|c], Y = [d,e,Z|f], Z = [g,h,X|i], \+ acyclic_term(X).
/* term_minimal(X, Y) */
runner_pred(term_minimal,2, extend, cyclic, 'XLOG 5.2.1').
runner_case(term_minimal,2, extend, cyclic, 'XLOG 5.2.1, XLOG 1') :-
X = f(f(f(X))),
term_minimal(X, Y), term_decompose(Y, [S|L]),
L == [S = f(S)].
runner_case(term_minimal,2, extend, cyclic, 'XLOG 5.2.1, XLOG 2') :-
Y = f(Y), X = g(g(X,f(Y)),Y), Z = h(Z),
term_minimal(X-Z, T), term_decompose(T, [S|L]),
L = [C=_, B=_, A=_], S == B-C, L == [C = h(C), B = g(B,A), A = f(A)].
runner_case(term_minimal,2, extend, cyclic, 'XLOG 5.2.1, XLOG 3') :-
X = f(f(f(X))), Y = f(f(Y)),
term_minimal(X-Y, T), term_decompose(T, [S|L]),
L = [A=_], S == A-A, L == [A = f(A)].
runner_case(term_minimal,2, extend, cyclic, 'XLOG 5.2.1, XLOG 4') :-
X = a(f(X,Y)), Y = a(f(Y,X)),
term_minimal(X-Y, T), term_decompose(T, [S|L]),
L = [A=_], S == A-A, L == [A = a(f(A, A))].
/* term_decompose(X, Y) */
runner_pred(term_decompose,2, extend, cyclic, 'XLOG 5.2.2').
runner_case(term_decompose,2, extend, cyclic, 'XLOG 5.2.2, XLOG 1') :-
X = f(f(f(X))),
term_decompose(X, [S|L]),
L == [S = f(f(f(S)))].
runner_case(term_decompose,2, extend, cyclic, 'XLOG 5.2.2, XLOG 2') :-
Y = f(Y), X = g(g(X,f(Y)),Y), Z = h(Z),
term_decompose(X-Z, [S|L]),
L = [C=_, B=_, A=_], S == B-C, L == [C = h(C), B = g(g(B,f(A)),A), A = f(A)].
runner_case(term_decompose,2, extend, cyclic, 'XLOG 5.2.2, XLOG 3') :-
X = f(f(f(X))), Y = f(f(Y)),
term_decompose(X-Y, [S|L]),
L = [B=_, A=_], S == A-B, L == [B = f(f(B)), A = f(f(f(A)))].
runner_case(term_decompose,2, extend, cyclic, 'XLOG 5.2.2, XLOG 4') :-
X = a(f(X,Y)), Y = a(f(Y,X)),
term_decompose(X-Y, [S|L]),
L = [A=_, B=_], S == A-B, L == [A = a(f(A,B)), B = a(f(B,A))].
/* map_compact(X, Y) */
runner_pred(map_compact,2, extend, cyclic, 'XLOG 5.2.3').
runner_case(map_compact,2, extend, cyclic, 'XLOG 5.2.3, XLOG 1') :-
X = s(s(X,Y),A), Y = s(Y,X),
map_compact([U=X,V=Y], [U=T,P,Q,V=S]),
P == (T = s(s(T, S), A)), Q == (S = s(S, T)).
runner_case(map_compact,2, extend, cyclic, 'XLOG 5.2.3, XLOG 2') :-
Y = s(s(Y,B),B), X = s(s(X,Y),A),
map_compact([U=Y,V=X], [U=S,P,V=T,Q]),
P == (S = s(S, B)), Q == (T = s(s(T, S), A)).
runner_case(map_compact,2, extend, cyclic, 'XLOG 5.2.3, XLOG 3') :-
X = s(s(X,Y),A), Y = s(s(Y,B),B),
map_compact([U=X,V=Y], [U=T,P,Q,V=S]),
P == (T = s(s(T, S), A)), Q == (S = s(S, B)).
runner_case(map_compact,2, extend, cyclic, 'XLOG 5.2.3, XLOG 4') :-
X = s(A,Y), Y = s(B,X),
map_compact([U=X,V=Y], [U=T,P,V=S]),
P == (T = s(A, V)), S == s(B, T).
runner_case(map_compact,2, extend, cyclic, 'XLOG 5.2.3, XLOG 5') :-
X = s(A,Y), Y = s(B,X), Z = s(C,Y),
map_compact([U=X,V=Y,W=Z], [U=T,P,V=S,W=R]),
P == (T = s(A, V)), S == s(B, T), R == s(C, V).