Re: Help: Multiple Proof Trees
- From: Bart Demoen <bmd@xxxxxxxxxxxxxxxxx>
- Date: Tue, 30 Aug 2005 08:46:50 +0200
Pasquale Renna wrote:
Let's take this small program as an example:
:- op(500, xfy, <==).
prove(true, true). prove( (Goal1, Goal2), (Proof1, Proof2) ) :- prove(Goal1, Proof1), prove(Goal2, Proof2). prove( Goal, Goal <== Proof) :- clause(Goal, Body), prove(Body, Proof).
a :- b,c. a :- e. b. c. e.
The goal prove(a, Proof) succeeds for the first time, but it gives errors on backtracking. Any suggestions on obtaining all the proof trees for a specified goal? Thanks in advance!
For future use: don't say "it gives errors on backtracking", say "the error message is 'ERROR: clause/2: No permission to access private_procedure `true/0''"
The problem occurs because backtracking causes the last clause to be activated with Goal equal to true, and the goal clause(true,Body) results in the error message. You could adapt the program as follows:
prove(true, true). prove( (Goal1, Goal2), (Proof1, Proof2) ) :- prove(Goal1, Proof1), prove(Goal2, Proof2). prove( Goal, Goal <== Proof) :- Goal \== true, clause(Goal, Body), prove(Body, Proof).
However, you will next observe something weird (if you are using SWI): you get answers like
Proof = a<== (b, c)<== (b, c)<== (b<==true, c<==true)
because SWI make ?- clause((A,B),C). succeed [Jan, is that a bug (using 5.5.3) ?] Other systems will give you an error similar to the one for true.
So you should also prevent backtracking from the second to the third clause ... maybe better use some cuts, as in
prove(true, Proof) :- !, Proof = true.
prove( (Goal1, Goal2), Proof) :- !, Proof = (Proof1, Proof2),
prove(Goal1, Proof1),
prove(Goal2, Proof2).
prove( Goal, Goal <== Proof) :-
clause(Goal, Body),
prove(Body, Proof).BTW, SWI allows you to do clause/2 on a (and b ...) but in other systems, you need to declare them dynamic.
Cheers
Bart Demoen .
- Follow-Ups:
- Re: Help: Multiple Proof Trees
- From: Jan Wielemaker
- Re: Help: Multiple Proof Trees
- References:
- Help: Multiple Proof Trees
- From: Pasquale Renna
- Help: Multiple Proof Trees
- Prev by Date: Help: Multiple Proof Trees
- Next by Date: Re: Help: Multiple Proof Trees
- Previous by thread: Help: Multiple Proof Trees
- Next by thread: Re: Help: Multiple Proof Trees
- Index(es):
Relevant Pages
|
|