|
UNDER CONSTRUCTION
THORN (Theorem prover based on HORN clause logic) is a program designed for solving problems in first-order logic
with equality. It runs on top of Shen Prolog and has been timed up to 42 MLips on Schubert's Steamroller. THORN is a lineal decendent of
the Stickel's Prolog Technology Theorem Prover.
The definitive paper explaining THORN is here.
THORN is included in the Shen Library that comes with the kernel sources download. The standard library is
required to load and run THORN. We recommend using ShenJIT for maximum performance and this link will give you a fast
native code executable Shen under Windows with the standard library installed. Assuming you've downloaed this fire
up the REPL by clicking on shen-jit-stlibN.exe (N is the version number) to get the REPL. To install THORN,
enter the following
(cd "Lib/THORN")
(load "datatypes.shen")
(load "THORN.shen")
(tc +)
to enable the type checker. The cd command means that your current directory is Lib/THORN. You are now ready to go.
Props
THORN reasons over first-order propositions (props). The THORN installation recognises prop as a type. Here are some props.
(4+) p
p : symbol
(5+) p : prop
p : prop
(6+) [p => q]
[p => q] : (list symbol)
(7+) [p => q] : prop
[p => q] : prop
(8+) [p => [q v r]]
[p => [q v r]] : prop |
These examples show there is an overlap between native types and THORN; p is a symbol but is also a
prop and [p => q] is a list of symbols and also a prop.
Propositional Calculus
The syntax for propositional calculus in THORN is as follows.
1. A lowercase symbol on its own which is not a logical constant is a prop.
The logical constants are ~, =>, <=>, &, v
2. If P and Q are props so are [~ P], [P v Q], [P & Q], [P => Q], [P <=> Q]
The two basic functions for running THORN are kb-> (insert in knowledge base) and <-kb (prove from knowledge base)
of types (list prop) --> symbol and prop --> boolean respectively. If the prop is provable then <-kb returns true. A proof
is sent to the file prf.txt in the current directory.
THORN is sound, complete and terminating wrt propositional calculus. Hence any tautology will be proved by <-kb.
(5+) (<-kb [[p => q] <=> [[~ q] => [~ p]]])
run time: 0.0018212000000019657 secs
416 inferences, equality = false
depth = 20, complexity = -1, timeout = 5 secs
true : boolean
|
<-kb returns true only if it solves the problem and in
that event returns a proof. Note this proof was gained without assuming any axioms
and we term these zero-axiom problems.
The Proof in THORN
If you look at your current directory Lib/THORN you see you will have a new file prf.txt which contains the proof of
the tautology. It contains examples of 4 of the 9 rules of inference which drive THORN. Here is the proof.
=============================
Step 1
? ((p => q) <=> ((~ q) => (~ p)))
> herbrandise
Herbrandisation in THORN converts a prop to prenex form where the matrix is in CNF;
it then eliminates the universal quantifiers. This is a bit more powerful that what is
generally called Herbrandisation - which just includes quantifier elimination. But
THORN bundles together the necessary preliminary steps in its version.
Here there are no quntifiers so what results is simply a prop in CNF. THORN prints proofs using
(...)s for readability.
=============================
Step 2
? ((((q v (~ p)) v p) & ((q v (~ p)) v (~ q))) & ((((~ p) v q) v (~ q)) & (((~ p) v q) v p)))
> &r
|=============================
|Step 3
|
|? (((q v (~ p)) v p) & ((q v (~ p)) v (~ q)))
|
|
|> &r
This is & right; prove a conjunction by proving the constituents. THORN indents the
proof to show that there are goals are stacking up; n indents = n+1 unsolved goals.
||=============================
||Step 4
||
||? ((q v (~ p)) v p)
||
||
||> hypdisj
There is no logical name for this operation AFAIK; I call it 'hypothetical disjunction'. It
means given a disjunction to prove, pick one atom from the disjunction and make it the goal assuming
the complements of the remainder. Here THORN chooses p.
||=============================
||Step 5
||
||? p
||
||1. p
||2. (~ q)
||
||> hyp
Proof by hypothesis; the rest of the proof flows naturally.
|=============================
|Step 6
|
|? ((q v (~ p)) v (~ q))
|
|
|> hypdisj
|=============================
|Step 7
|
|? (~ q)
|
|1. p
|2. (~ q)
|
|> hyp
=============================
Step 8
? ((((~ p) v q) v (~ q)) & (((~ p) v q) v p))
> &r
|=============================
|Step 9
|
|? (((~ p) v q) v (~ q))
|
|
|> hypdisj
|=============================
|Step 10
|
|? (~ q)
|
|1. (~ q)
|2. p
|
|> hyp
=============================
Step 11
? (((~ p) v q) v p)
> hypdisj
=============================
Step 12
? p
1. (~ q)
2. p
> hyp
Thse are all the operations needed to define a sound, complete and terminating ATP for propositional calculus.
Next we will move from zero-axiom proposotional problems to quantified problems.
Zero and Non-Zero Axiom Problems
The preceding problem is a *zero-axiom problem*. No assertions are made using kb-> and hence no axioms are assumed.
Now we will look at an 3 axiom problem where we assume [[p v q] [[~ p] v r] [[~ q] v r]] and prove for r. We'll see that the
proof is a little different.
(12+) (kb-> [[p v q] [[~ p] v r] [[~ q] v r]])
compiled : symbol
(13+) (<-kb r)
run time: 0.0018338999943807721 secs
274 inferences, equality = false
depth = 20, complexity = -1, timeout = 5 secs
true : boolean
|
=============================
Step 1
? r
> herbrandise
=============================
Step 2
? r
> hypdisj
============================= <------- axioms take over here
Step 3
? r
1. (~ r)
> (r <-- p)
=============================
Step 4
? p
1. (~ r)
> (p <-- (~ q))
=============================
Step 5
? (~ q)
1. (~ p)
2. (~ r)
> ((~ q) <-- (~ r))
=============================
Step 6
? (~ r)
1. q
2. (~ p)
3. (~ r)
> hyp
The non-zero case works differently. We cannot prove the result without using the axiom base.
THORN compiles the axioms to *contrapositives* - which are rather like the clauses in a logic
program except ~ can be used. The first two steps are as before; no changes result from Herbrandisation
and hypdisj. The point at which the axioms are called is marked. The complement of the conclusion is
inserted into the list of assumptions. It is always a valid move to assert the complement of what one
trying to prove and THORN does this continuously.
In Step 4, we see this clearly. THORN invokes (p <-- (~ q)) from the axiom set and the following
step includes (~ p) as an assumption. This combination of backward chaining (in the manner of Prolog) and the
insertion of complements (in the manner of indirect proof) is called *indirect chaining* in THORN. Finally we
backchain to (~ r) and the proof is closed by hypothesis.
Incompleteness for PC in Non-Zero Axiom Cases
The PTTP is sound and complete provided that the axioms given to it are consistent. THORN, like the PTTP,
works under the assumption that the axioms supplied to it are consistent. When that fails,
THORN can fail (this is also true of methods like set-of-support resolution). THORN is the same; given
(kb-> [p [~ p]]) and (<-kb q), THORN fails to be find a proof. There is no contrapositive in the axiom
bases whose head is q. But if [[p & [~ p]] => q] is given as a problem in a zero axiom setting, true is
returned.
First Order Logic
For FOL we extend the syntax to first-order props.
3. If X and Y are symbols (other than logical constants), strings, booleans (true or false), or numbers
then X and Y are terms. If F is a lowercase symbol (other than a logical constant) and X1 ... Xn are terms
then [F X1 ...Xn] is a term.
4. If G is a lowercase symbol (other than a logical constant) and X1...Xn are terms then [G X1 ...Xn] is a prop.
5. If X and Y are terms then [X = Y] is a prop.
6. If P is a prop so are [all X P] and [exists X P] where X is a lowercase symbol other than a logical constant.
Prolog Notation
The above syntax rules allow terms to be capitalised. In such cases the these terms are treated as variables
(in the manner of Prolog). Thus [all x [[f x] => [h x]]] and [[f X] => [g X]] are equivalent in meaning.
Incompleteness for FOL in the Zero Axiom Case
In the zero axiom case, THORN is sound, incomplete and terminating wrt FOL.
In this context THORN functions as a weak first-order prover (see the paper for why this is so).
First Order Problems
It is more powerful when
a list of props is submitted to kb-> as axioms. In this case THORN compiles the axioms into a logic program
designed to solve queries posed wrt those axioms. In the THORN/Problems directory you will find many such files containing
axioms for different systems. To run these simply type (load "") You'll find an md file in that directory
giving performance times.
Here is a guide to the problems in that file .
|
File | Contents |
|
ec.shen | Equivalential calculus axioms. These problems are impossible for humans. |
|
group.shen | Group theory which requires equality. The same problem is submitted with unbounded and
differing levels of complexity. |
|
L.shen | A first-order formalisation of classical propositional calculus incorporating modus ponens and
three axiom schemas taken from Eliot Mendelson. The axiomatisation is in Prolog notation. |
|
PC.shen | A selection of propositional problems from Pelletier. |
|
schubert.shen | Schubert’s steamroller. |
|
set.shen | Basic set theory |
|
meaning.shen | Tarsi-style truth semantics of natural language |
Schubert's Steamroller
Schubert's Steamroller is a famous problem in automated reasoing that remained unsolved
by computer until 1985. It is now pretty commonplace for ATPs (automated theorem provers) to
solve Schubert's Steamroller and THORN can solve it very quickly. Here is the problem.
Wolves, foxes, birds, caterpillars, and snails are animals, and there are some of each.
Also there are some grains, and grains are plants.
Every animal either likes to eat all plants, or, all animals much smaller than itself that like
to eat some plants.
Caterpillars and snails are much smaller than birds, which are much smaller than foxes, which in
turn are much smaller than wolves. Wolves do not like to eat foxes or grains, while birds like
to eat caterpillars but not snails. Caterpillars and snails like to eat some plants.
Therefore prove there is an animal that likes to eat a grain-eating animal.
To run Schubert's Steamroller, load schubert.shen.
(15+) (cd "Lib/THORN/Problems")
"Lib/THORN/Problems/" : string
(16+) (load "schubert.shen")
set : symbol
(fn schubert) : (--> symbol)
compiled : symbol
(fn steamroller) : (--> prop)
run time: 0.13231110002379864 secs
5093070 inferences, equality = false
depth = 20, complexity = -1, timeout = 5 secs
true : boolean
run time: 0.29963100000168197 secs
typechecked in 10819 inferences
loaded : symbol
|
If we peek inside the file we find it consists of a 0-place function 'schubert' which
lists a set of axioms and invokes kb-> on them. Also further down there is a function 'steamroller'
that defines the problem posed. By calling 'schubert' we compile axioms to code and by
calling kb-> on 'steamroller' we attempt to solve the problem. We do all this by loading the
file. As you can see the attempt is successful. (The thorn.defaults just sets the search settings
to the default.)
(thorn.defaults)
(define schubert
{--> symbol}
-> (kb-> [ [all x [[wolf x] => [animal x]]]
[all x [[fox x] => [animal x]]]
[all x [[bird x] => [animal x]]]
[all x [[caterpillar x] => [animal x]]]
[all x [[snail x] => [animal x]]]
[all x [[grain x] => [plant x]]]
[exists x [wolf x]]
[exists x [fox x]]
[exists x [bird x]]
[exists x [caterpillar x]]
[exists x [snail x]]
[exists x [grain x]]
[all x [[animal x] => [[all y [[plant y] => [eats x y]]]
v
[all z [[[[animal z] &
[smaller z x]] &
[exists u [[plant u] & [eats z u]]]]
=>
[eats x z]]]]]]
[all x [all y [[[caterpillar x] & [bird y]] => [smaller x y]]]]
[all x [all y [[[snail x] & [bird y]] => [smaller x y]]]]
[all x [all y [[[bird x] & [fox y]] => [smaller x y]]]]
[all x [all y [[[fox x] & [wolf y]] => [smaller x y]]]]
[all x [all y [[[bird x] & [caterpillar y]] => [eats x y]]]]
[all x [[caterpillar x]
=> [exists y [[plant y] & [eats x y]]]]]
[all x [[snail x]
=> [exists y [[plant y] & [eats x y]]]]]
[all x [all y [[[wolf x] & [fox y]] => [~ [eats x y]]]]]
[all x [all y [[[wolf x] & [grain y]] => [~ [eats x y]]]]]
[all x [all y [[[bird x] & [snail y]] => [~ [eats x y]]]]] ]))
(schubert)
(define steamroller
{--> prop}
-> [exists x [exists y [[[animal x] &
[animal y]] &
[[eats x y] &
[all z [[grain z] => [eats y z]]]]]]])
(<-kb (steamroller))
The proof, as ever, is in prf.txt in Lib/THORN/Problems. It is 78 steps long and too
long to quote here but opens thus.
=============================
Step 1
? (exists x (exists y
(((animal x) & (animal y)) & ((eats x y) & (all z ((grain z) => (eats y z)))))))
> herbrandise
=============================
Step 2
? (exists x10251 (exists x10252
(((animal x10251) & (animal x10252)) & ((eats x10251 x10252)
& ((~ (grain (f10254 x10251 x10252))) v (eats x10252 (f10254 x10251 x10252)))))))
> eR
=============================
Step 3
? (exists x10252 (((animal Var184) & (animal x10252))
& ((eats Var184 x10252) & ((~ (grain (f10254 Var184 x10252)))
v (eats x10252 (f10254 Var184 x10252))))))
> eR
The step er (short for exists right) eliminates an existential quantifier by replacing the
bound variable by a free variable. he result here is effectively a conjunctive Prolog-style
query. This is another of the primitive inference rules of THORN in addition to the 5 already
learnt; herbrandise, &r, hypdisj, hyp and indirect chaining.
Equality Proofs
THORN adds 3 more rules to deal with equality.
1. =r; any goal of the form X = Y can be solved if X and Y unify.
2. rewriteA; given a goal P with a non-variable term occurrence x,
prove x=y where x and y are not syntactically identical and replace
the occurrence of x by y in P to create P* and try to prove P*.
3. rewriteB; given a goal P with a non-variable term occurrence x,
prove y=x where x and y are not syntactically identical and replace
the occurrence of x by y in P to create P* and try to prove P*.
If you load groups.shen in the Problems directory, you will solve two problems in group theory. The second
hsa proof as follows, displaying rewriteA and rewriteB.
=============================
Step 1
? (all x ((inv (inv x)) = x))
> herbrandise
=============================
Step 2
? ((inv (inv c10638)) = c10638)
> hypdisj
=============================
Step 3
? ((inv (inv c10638)) = c10638)
1. (~ ((inv (inv c10638)) = c10638))
> rewriteB (inv (inv c10638))
|=============================
|Step 4
|
|? ((+ e (inv (inv c10638))) = (inv (inv c10638)))
|
|1. (~ ((inv (inv c10638)) = c10638))
|
|> (((+ e X) = X) <--)
=============================
Step 5
? ((+ e (inv (inv c10638))) = c10638)
1. (~ ((inv (inv c10638)) = c10638))
> rewriteB e
|=============================
|Step 6
|
|? ((+ Var75 (inv Var75)) = e)
|
|1. (~ ((inv (inv c10638)) = c10638))
|
|> (((+ X (inv X)) = e) <--)
=============================
Step 7
? ((+ (+ c10638 (inv c10638)) (inv (inv c10638))) = c10638)
1. (~ ((inv (inv c10638)) = c10638))
> rewriteB (+ (+ c10638 (inv c10638)) (inv (inv c10638)))
|=============================
|Step 8
|
|? ((+ c10638 (+ (inv c10638) (inv (inv c10638)))) = (+ (+ c10638 (inv c10638)) (inv (inv c10638))))
|
|1. (~ ((inv (inv c10638)) = c10638))
|
|> (((+ X (+ Y Z)) = (+ (+ X Y) Z)) <--)
=============================
Step 9
? ((+ c10638 (+ (inv c10638) (inv (inv c10638)))) = c10638)
1. (~ ((inv (inv c10638)) = c10638))
> rewriteA (+ (inv c10638) (inv (inv c10638)))
|=============================
|Step 10
|
|? ((+ (inv c10638) (inv (inv c10638))) = e)
|
|1. (~ ((inv (inv c10638)) = c10638))
|
|> (((+ X (inv X)) = e) <--)
=============================
Step 11
? ((+ c10638 e) = c10638)
1. (~ ((inv (inv c10638)) = c10638))
> (((+ X e) = X) <--)
Controlling Search
(thorn.timeout n) sets the timeout in seconds for solving a problem; the default is 5 seconds. (thorn.complexity n) sets
the maximum complexity of any goal that can be taken as an object of proof. Goals beyond that level are prunded.
The default value is -1 meaning no goals are pruned this way. Complexity is measured by the number of terms in the
flattened goal. (thrn.equality true) invokes equality reasoning (this is invoked automatically if the axioms
include an equality or the problem contains one). (thorn.depth n) controls the depth of search measured by the longest branch
allowed; the default is 20. (thorn.defaults) restores the defaults.
Overwriting
THORN generates a function f for every predicate f in the axiom base. If f already exists in your implementation
then THORN will attempt to overwrite it. In the case of an stlib or system function an error will be generated when this
is tried. We will probably fix this in a later realease. kb-> however is not cumulative; it always overwrites. (thorn.wipe-kb)
will clear any residuee from any past axiomatisation.
|