
% File: tiger.pl
% Author: Peter Clark
% Purpose: Toy demonstration of LPE etc. working.
% Usage: Type | ?- demo. to run the demo.

:- ensure_loaded([lpe,utils]).

:- nl, nl, write('Type `| ?- demo.'' to start!'), nl, nl.

% --------------------

% declare non-operational goals:
:- dynamic tiger/1, carnivore/1, mammal/1, cat_family/1. 

tiger(X) :- striped(X), cat_family(X).

mammal(X) :- hairy(X).
mammal(X) :- gives_milk(X).
mammal(X) :- warm_blooded(X).
	
carnivore(X) :- eats_meat(X).
carnivore(X) :- pointed_teeth(X), mammal(X).

cat_family(X) :- carnivore(X), long_tail(X).
cat_family(X) :- fast_runner(X).

gives_milk(joe).
eats_meat(joe).
long_tail(joe).
striped(joe).

striped(mike).
pointed_teeth(mike).
fast_runner(mike).

warm_blooded(sue).
hairy(sue).

% ======================================================================

demo :-
	nl, 
	write('Demo of LPE. Just hit <return>! or CTRL-C to abort.'), 
	nl, nl, 
	member(Mode, [lpe,pe,ebg,none]),
	nl, write('========= demo of '), write(Mode), write(' ==========='), 
	nl, nl,
	demo(Mode),
	fail.
demo :-
	nl, 
	write('Here''s another demo of LPE, with variables in the goal!'),
	nl, nl, 
	write('
	Note that LPE and PE will find the soln (X=mike) with the `best''
	(= shortest, here) operational definition first, unlike EBG and no
        learning. This illustrates the definition ordering mechanism of 
        LPE and PE.'), nl, nl,
	member(Mode, [lpe,pe,ebg,none]),
	nl, write('========= demo2 of '), write(Mode), write(' ==========='), 
	nl, nl,
	demo2(Mode),
	fail.
demo :-
	write('==== End of Demo! ======'), nl.

demo(Mode) :-
	demo_goals([
		 set_tracing_mode(on),
		 set_learning_mode(Mode),
		 lpe_setup(tiger/1),
		 lpe_listing(tiger/1),
		 lpe_call(tiger(joe)),
		 lpe_listing(tiger/1),
		 lpe_call(tiger(mike)),
		 lpe_listing(tiger/1)]).

demo2(Mode) :-
	demo_goals([
		 set_tracing_mode(on),
		 set_learning_mode(Mode),
		 lpe_setup(tiger/1),
		 lpe_listing(tiger/1),
		 lpe_call(tiger(X)) - [X/'X'] - allsolns,
		 lpe_listing(tiger/1)]).

