:- set_prolog_flag(flowlog_engine, wam).

ok :-
    % copy_term/2 preserves sharing and makes fresh variables.
    copy_term(foo(X,Y), T1),
    T1 = foo(A,B),
    A \== B,
    copy_term(foo(X,X), T2),
    T2 = foo(C,D),
    C == D,
    copy_term(X, Y),
    X \== Y,
    X = foo(Z),
    copy_term(X, Y2),
    Y2 = foo(A2),
    var(A2),
    A2 \== Z,

    % term_variables/2 follows bindings and returns unique vars in order.
    X3 = foo(U,V),
    term_variables(X3, Vars0),
    Vars0 == [U,V],
    X4 = foo(W),
    X5 = X4,
    term_variables(X5, Vars1),
    Vars1 == [W],

    % numbervars/3 binds vars to '$VAR'(N) terms.
    numbervars(foo(N1,N2), 0, End),
    N1 == '$VAR'(0),
    N2 == '$VAR'(1),
    End == 2,

    % unify_with_occurs_check/2 rejects cyclic bindings.
    \+ unify_with_occurs_check(Q, f(Q)),
    unify_with_occurs_check(P, R),
    P == R,

    % subsumes_term/2 uses rigid spec variables (Spec must be an instance of Gen).
    subsumes_term(foo(S,1), foo(2,1)),
    \+ subsumes_term(foo(_S,1), foo(2,2)),
    subsumes_term(foo(S2,S2), foo(1,1)),
    \+ subsumes_term(foo(S3,S3), foo(1,2)),
    \+ subsumes_term(f(_), X6).

