-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprove_p.pl
41 lines (34 loc) · 966 Bytes
/
prove_p.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
% display a proof tree
prove_p(A):-prove_p(A,P),write_proof(P).
prove_p(A,P):-
( A=true -> P=[]
; A=(B,C) -> cl(B,D),conj_append(D,C,E),
prove_p(E,PE),P=[p(A,(B:-D))|PE]
; otherwise -> cl(A,B),prove_p(B,PB),
P=[p(A,(A:-B))|PB]
).
write_proof([]):-
write('...............[]'),nl.
write_proof([p(A,B)|Proof]):-
write((:-A)),nl,
write('.....|'),write('..........'),write(B),nl,
write('.....|'),write('..................../'),nl,
write_proof(Proof).
conj_append(A,B,C):-
( A=true -> B=C
; A=(A1,A2) -> C=(A1,C2),conj_append(A2,B,C2)
; otherwise -> C=(A,B)
).
% cl(H,B) <- (H:-B) is object-level clause
cl(rectangle,(polygon(4),angles(90))).
cl(square,(rectangle,regular)).
cl(triangle,polygon(3)).
cl(equilateral_triangle,(triangle,regular)).
%%% facts
cl(polygon(4),true).
cl(regular,true).
cl(angles(90),true).
/** <examples>
?- prove_p(rectangle).
?- prove_p(square).
*/