Please send questions to st10@humboldt.edu .
/* 335 Wk 9 Lect 2 Knowledge Base #1 for discussing Prolog cut */
/* last modified: 3-23-11                                      */

% adapted from Clocksin and Mellish, "Programming in Prolog",
%    pp. 64 - 78
%
% adapted by S. Tuttle

/*-----------------------------------------------------------------*/

/* 1 */ house_build(Plan) :- outside_build(Plan).
/* 2 */ house_build(Plan) :- build(self, Plan).

/* 3 */ outside_build([ contact(B) | Plan1 ]) :-
                                               builder(B), 
                                               loc(B, london), 
                                               !,
                                               build(B, Plan1).
/* 4 */ outside_build([ contact(B) | Plan1 ]) :-
                                               builder(B),
                                               build(B, Plan1).

/* 5 */ builder('Rousseau & Co').
/* 6 */ builder('D Morgan').
/* etc. */

/* 28 */ loc('Eiffel Tower', paris).
/* 29 */ loc('Rousseau & Co', paris).
/* 30 */ loc('D Morgan', london).
/* etc. */

/* 50 */ build(Builder, Plan) :- write(Builder), 
                                 nl, 
                                 write(Plan), nl.
               
/*-----------------------------------------------------------------*/

sum_to(1, 1) :- !.
sum_to(1, _) :- !, fail.
sum_to(N, Res) :- N1 is N-1,
                  sum_to(N1, Res1),
                  Res is Res1+N.

sum_to2(N, 1) :- N =< 1, !.         % note: less than or eq: =<
sum_to2(N, R) :- N1 is N-1,
                 sum_to2(N1, R1),
                 R is R1+N.

/*-----------------------------------------------------------------*/

my_not(P) :- P, !, fail.
my_not(P).

/*-----------------------------------------------------------------*/

foreigner(george).
avg_taxpayer(X) :- foreigner(X), !, fail.
avg_taxpayer(X) :- spouse(X, Y), gross_income(Y, Inc),
                   Inc > 30000, !, fail.

gross_income(X, Y) :- receives_pension(X, P), P < 5000, !, fail.OA