-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwang_min.pl
90 lines (76 loc) · 1.59 KB
/
wang_min.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
% Automated Theorem Proving
% Wangs Algorithm
% Define operators.
:-op(700,xfy,<->).
:-op(700,xfy,->).
:-op(600,xfy,v).
:-op(600,xfy,&).
:-op(500,fy,!).
% Main call.
prove([],[]):-nl.
prove([L|P],[R|A]):-
nl, write(L), write(' |= '), write(R), nl,
wang(L,R),
prove(P,A).
% Procedure of Wang to prove theorem.
wang(L,R):-
rules(L,R),
write('TRUE').
wang(_,_):-
write('FALSE').
% Move negations from left to right.
rules(L,R):-
member(!X,L),
select(!X,L,Ld),
rules(Ld,[X|R]).
% Move negations from right to left.
rules(L,R):-
member(!X,R),
select(!X,R,Rd),
rules([X|L],Rd).
% Replace conjunction by commas on the left.
rules(L,R):-
member(X & Y,L),
select(X & Y,L,Ld),
rules([X,Y|Ld],R).
% Replace disjunction by commas on the right.
rules(L,R):-
member(X v Y,R),
select(X v Y,R,Rd),
rules(L,[X,Y|Rd]).
% Branch disjunction on the left.
rules(L,R):-
member(X v Y,L),
select(X v Y,L,Ld),
rules([X|Ld],R),
rules([Y|Ld],R).
% Branch conjunction on the right.
rules(L,R):-
member(X & Y,R),
select(X & Y,R,Rd),
rules(L,[X|Rd]),
rules(L,[Y|Rd]).
% Replace implication on the left.
rules(L,R):-
member(X -> Y,L),
select(X -> Y,L,Ld),
rules([!X v Y|Ld],R).
% Replace implication on the right.
rules(L,R):-
member(X -> Y,R),
select(X -> Y,R,Rd),
rules(L,[!X v Y|Rd]).
% Replace equivalence on the left.
rules(L,R):-
member(X <-> Y,L),
select(X <-> Y,L,Ld),
rules([(X -> Y) & (Y -> X)|Ld],R).
% Replace equivalence on the right.
rules(L,R):-
member(X <-> Y,R),
select(X <-> Y,R,Rd),
rules(L,[(X -> Y) & (Y -> X)|Rd]).
% Finally compare both sides.
rules(L,R):-
member(X,L),
member(X,R).