proofs - adding proofs to a predicate prior to compilation
------

Files in this directory:

proof.ptn   - ptn code to translate a Prolog program into one with "proofs"
proof_gr.gr - the DCG grammar for Prolog 
solve.nl    - simple meta interpreter for generating proofs at run-time
blocks.nl   - Prolog program for testing (Sterling & Shapiro blocks world)
water.nl    - Prolog program for testing (Luger & Stubblefield - water jugs)
bible.nl    - Prolog program for testing (S & S)
timings.nl  - Code for comparing the times of the two methods


To run
------

% ../../ptn			% load ptn

Nu-Prolog 1.6.4
1?- ptn2nl(proof).		% translate the ptn code into Prolog
true.				% this takes a few seconds
				% required ONCE only
2?- gr2nl(proof_gr).		% translate grammar rules
true.				% required ONCE only

3?- consult(proof_gr).		% consult the grammar rules
Consulting proof_gr.nl
Warning: descendent/2 redefined	% ignore warning
true.

4?- consult(proof).		% consult the proof builder 
Consulting proof.nl
true.

5?- proof(blocks).		% build the proofs for the blocks
true.				% world problem, and add as extra
				% argument - output in blocksProof.nl

6?- proof(water).		% same for water.nl => waterProof.nl
true.

7?- consult(blocksProof).	% consult the blocks with proofs file
Consulting blocksProof.nl
true.

8?- test_plan( test, Plan, Proof). 		% try it out
Proof = (test_plan(test, [to_place(a, b, q), ....
....
Plan = [to_place(a, b, q), to_block(b, p, c), ....
.....
9?- consult(waterProof).	% try the water jugs example
Consulting waterProof.nl
true.

10?- go( state(5, 0),state(2, 3), Path, Proof).
Proof = 
....

Path =  
....


				% Inspect the *Proof.nl files

Some Explanation
----------------
This example is one where PTN is used as a means to provide a proof tree
as a goal is solved, by pre-building the proof and adding it to
the goal as an extra argument. 
The more common way of providing such a proof is by using a meta-interpreter
which builds the proof at run time.

The code is in proof.ptn, written in ptn as this was developed around the
same time as the "ptn" interpreter itself (ptn2nl). Each clause is
examined in turn, and extra arguments are added to the goals, which form
the basis of a proof tree.

Example files are blocks.nl, water.nl and bible.nl

A predicate son/2:
	
son( X, Y) :-
	father( Y, X),
	male( X). 

is translated into:

son( X, Y, (( son( X, Y):- Z1, Z2)):-
        father( Y, X, Z1),
 	male( X, Z2).

and stored in blocksProof.nl, waterproof.nl or bibleProof.nl etc.


Comparison with the meta-interpreter
-----------------------------------
timings/1 (in timings.nl)  provides some CPU times to compare the methods
of simple meta-interpreter v. pre-compiled proofs.
There is some speed up if most of the files are compiled instead.
(Nu-Prolog command nc -c proof.nl)
The blocks.nl and water.nl files should not be compiled because "solve"
makes a call to clause/2 which requires the predicates to be dynamic. 
 
To run this program:

% ../../ptn

1?- consult(timings).
Consulting timings.nl.
Consulting proof_gr.nl.
Warning: descendent/2 redefined
done
Consulting proof.nl.
done
Consulting blocks.nl.
done
Consulting solve.nl.
done
Consulting water.nl.
done
true.
2?- timings(blocks).
Solving the "blocks world" problem using S & S meta interpreter

CPU time: 0.92 seconds

Pre-proofing the blocks.nl file - to produce blocksProof.nl

CPU time: 2.699  seconds
Consulting /mount/muse/staff/liz/ptn/apps/proofs/blocksProof.nl.
done

Solving the "blocks world" problem using pre-compiled proofs

CPU time: 0.03 seconds

true.
3?- timings(water).
Solving the "water jugs" problem using S & S meta interpreter

CPU time: 2.66 seconds

Pre-proofing the water.nl file - to produce waterProof.nl

CPU time: 1.39  seconds
Consulting /mount/muse/staff/liz/ptn/apps/proofs/waterProof.nl.
done

Solving the "water jugs" problem using pre-compiled proofs

CPU time: 0.06 seconds

true.

{Liz Haywood May 1994}

