% Prova 1.9
% Demonstrating the use of tabling

:- eval(consult('../ContractLog/math.prova')).

:- solve(shaves(X,Y)).

person(barber).
person(mayor).

shaves(barber,Person) :-
	person(Person),
	tnot(shaves(Person,Person)).

:- solve(win(X)).

win(X) :-
	move(X,Y),
	tnot(win(Y)). 

move(a,a). 
move(a,b). 
move(b,a). 
move(b,c). 

:- solve(hasParent(child1,abcde)).
:- solve(hasParent(child2,abcdef)).

hasParent(child1,abcd).
hasParent(child2,abcd).
hasParent(child2,abcde).
hasParent(child1,abcde) :- tnot(hasParent(child1,abcde)).

sibling(Child1, Child2):-
    childIn(Child1, Family),
    childIn(Child2, Family),
    tnot(eq(Child1, Child2)).

childIn(a,f1).
childIn(b,f1).

eq(X,X).

:- solve(sibling(X,Y)).

%%% tnot
tnot([X|Args]) :-
	cache([X|Args]),
	!,
	fail().
tnot([X|Args]).
