Sorry. I thought it is clear without source. demorgan/3
below
is a renamed predicate for readability. iterated_deepening
should be clear, which is a wrapper for call_with_depth_limit/4
lk(E):- lk(E, 10, 10, 10).
%
lk(E, L, D, N):- iterated_deepening(lk_left(-E, [], [], [], L, 0), D, N, R),
writeln(depth_limit_info = R).
%
lk(E, L):- lk_left(-E, [], [], [], L, 0).
% Borrowed from leanTAP.
lk_left((E,F), A, B, C, D, N) :-!,
lk_left(E, [F|A], B, C, D, N).
lk_left((E;F), A, B, C, D, N) :-!,
lk_left(E, A, B, C, D, N),
lk_left(F, A, B, C, D, N).
lk_left((E->F), A, B, C, D, N) :-!,
lk_left((-E; F), A, B, C, D, N).
lk_left(all(I,J), A, B, C, D, N) :-!,
\+length(C,D),
copy_term((I,J,C), (G,F,C)),
append(A, [all(I,J)], E),
lk_left(F, E, B, [G|C], D, N).
lk_left(some(I,J), A, B, C, D, N) :-!,
copy_term((I,J,C), (G,F,C)),
numbervars(G, N, N0),
lk_left(F, A, B, C, D, N0).
lk_left(-E, A, B, C, D, N):- demorgan(E, E0), !,
lk_left(E0, A, B, C, D, N).
lk_left(A, _, [C|D], _, _, N) :-
( (A = -(B); -(A) = B) ->
( unify_with_occurs_check(B, C)
; lk_left(A, [], D, _, _, N)
)
).
lk_left(A, [E|F], B, C, D, N) :- lk_left(E, F, [A|B], C, D, N).
%
demorgan(-E, E).
demorgan((E;F), (-E, -F)).
demorgan((E,F), (-E; -F)).
demorgan((E->F), (E, -F)).
demorgan(all(I, J), some(I, -J)).
demorgan(some(I, J), all(I, -J)).