% ================================================================= % == == % == An Introduction to ARTIFICIAL INTELLIGENCE == % == Janet Finlay and Alan Dix == % == UCL Press, 1996 == % == == % ================================================================= % == == % == handles lists of positive and negative conditions == % == used as a representation in several examples == % == == % == Prolog example, Alan Dix, September 1997 == % == == % ================================================================= % test_one_cond/2, set_one_cond/3 - primarily for internal use % test_cond_list/2, set_cond_list/3, diff_cond_list/3 % Uses: % member/2, add_member/3, remove_member/3 - from file 'list.p' % Please: % consult('../util/list.p'). % a condition list contains some elements of the form 'not X' % for some term X test_one_cond(not X,S) :- !, not member(X,S). test_one_cond(X,S) :- member(X,S). set_one_cond( not X, Sold, Snew ) :- !, remove_member( X, Sold, Snew ). set_one_cond( X, Sold, Snew ) :- add_member( X, Sold, Snew ). test_cond_list([],S). test_cond_list([Cond|Rest],S) :- test_one_cond(Cond,S), test_cond_list(Rest,S). set_cond_list([],S,S). set_cond_list([Cond|Rest],Sold,Snew) :- set_one_cond(Cond,Sold,Sone), set_cond_list(Rest,Sone,Snew). diff_cond_list([],S,[]). diff_cond_list([Cond|Rest],S,Diff) :- test_one_cond(Cond,S), !, diff_cond_list(Rest,S,Diff). diff_cond_list([Cond|Rest],S,[Cond|Diff]) :- % Cond must be false diff_cond_list(Rest,S,Diff).