friends(phil,robin).
friends(chris,robin).
friends(phil,pat).
friends(jo,chris).
invitation(phil).
invitation(pat).
party(P) :- invitation(P).
party(P) :- friends(P,F),invitation(F).
party(P) :- friends(F,P),invitation(F).
pals(P,F) :- friends(P,F).
pals(P,F) :- friends(F,P).
party(P) :- pals(P,F),invitation(F).
invitation(eric).
popular(P) :- party(P),!,no_computer_talk(P).
operands(X+Y,X,Y).
sumsq(X,Y,Z) :- Z is (X*X)+(Y*Y).
sum(0,0).
sum(N,S) :- N1 is N-1, sum(N1,S1),S is S1+N.
check_invitations(N) :- 
 asserta(count(0)),
 count_invitations(N).
increment :-
 retract(count(N)), N1 is N+1,
 asserta(count(N1)), !, fail.
count_invitations(N) :- invitation(P),increment.
count_invitations(N) :- retract(count(N)).
