|
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
2 % An Implementation of G4ip for Terzo |
|
3 % author: Christian.Urban@cl.cam.ac.uk |
|
4 % |
|
5 % some solvable sample queries: |
|
6 % |
|
7 % prove (nil |- p imp p). |
|
8 % prove (nil |- (p imp p) imp (p imp p)). |
|
9 % prove (nil |- ((((p imp q) imp p) imp p) imp q) imp q). |
|
10 % prove (nil |- (a imp (b imp c)) imp ((a imp b) imp (a imp c))). |
|
11 % prove (nil |- (a or (a imp b)) imp (((a imp b) imp a) imp a)). |
|
12 % |
|
13 % two non-solvable queries |
|
14 % |
|
15 % prove (nil |- a or (a imp false)). |
|
16 % prove (nil |- ((a imp b) imp a) imp a). |
|
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
18 |
|
19 module G4ip. |
|
20 |
|
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
22 % atomic formulae |
|
23 kind form type. |
|
24 |
|
25 type p form. |
|
26 type q form. |
|
27 type a form. |
|
28 type b form. |
|
29 type c form. |
|
30 |
|
31 type isatomic form -> o. |
|
32 |
|
33 isatomic p. |
|
34 isatomic q. |
|
35 isatomic a. |
|
36 isatomic b. |
|
37 isatomic c. |
|
38 |
|
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
40 % logical operators |
|
41 type false form. |
|
42 type and form -> form -> form. |
|
43 type or form -> form -> form. |
|
44 type imp form -> form -> form. |
|
45 |
|
46 infixr and 9. |
|
47 infixr or 9. |
|
48 infixr imp 9. |
|
49 |
|
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
51 % sequent constructor; sequents are of the form: (list |- formula) |
|
52 kind seq type. |
|
53 |
|
54 type |- list form -> form -> seq. |
|
55 infixl |- 4. |
|
56 |
|
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
58 % prove predicate; prints "solvable" if seq is provable, otherwise "no" |
|
59 type prove seq -> o. |
|
60 |
|
61 prove (Gamma |- G) :- ( membNrest P Gamma Gamma', |
|
62 left (P::Gamma' |- G) ); |
|
63 right (Gamma |- G). |
|
64 |
|
65 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
66 % rightrules |
|
67 type right seq -> o. |
|
68 |
|
69 right (Gamma |- B and C) :- prove (Gamma |- B), %% and-R |
|
70 prove (Gamma |- C). |
|
71 |
|
72 right (Gamma |- B imp C) :- prove (B::Gamma |- C). %% imp-R |
|
73 |
|
74 right (Gamma |- B or C) :- prove (Gamma |- B); %% or-R |
|
75 prove (Gamma |- C). |
|
76 |
|
77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
78 % leftrules |
|
79 type left seq -> o. |
|
80 |
|
81 left (false :: Gamma |- G). %% false-L |
|
82 |
|
83 left (A :: Gamma |- A) :- isatomic A. %% axiom |
|
84 |
|
85 left (B and C::Gamma |- G) :- prove (B::C::Gamma |- G). %% and-L |
|
86 |
|
87 left (B or C::Gamma |- G) :- prove (B::Gamma |- G), %% or-L |
|
88 prove (C::Gamma |- G). |
|
89 |
|
90 |
|
91 left (A imp B::Gamma |- G) :- %% imp-L1 |
|
92 isatomic A, ismember A Gamma, prove (B::Gamma |- G). |
|
93 |
|
94 left ((B and C) imp D::Gamma |- G) :- %% imp-L2 |
|
95 prove (B imp (C imp D)::Gamma |- G). |
|
96 |
|
97 left ((B or C) imp D::Gamma |- G) :- %% imp-L3 |
|
98 prove (B imp D::C imp D::Gamma |- G). |
|
99 |
|
100 left ((B imp C) imp D::Gamma |- G) :- %% imp-L4 |
|
101 prove (C imp D::Gamma |- B imp C), |
|
102 prove (D::Gamma |- G). |
|
103 |
|
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
105 % returns a member and the remainder of a list |
|
106 type membNrest A -> list A -> list A -> o. |
|
107 |
|
108 membNrest X (X::Rest) Rest. |
|
109 membNrest X (Y::Tail) (Y::Rest) :- membNrest X Tail Rest. |
|
110 |
|
111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
112 % succeeds only once if A is element in the list |
|
113 type ismember A -> list A -> o. |
|
114 |
|
115 ismember X (X::Rest) :- !. |
|
116 ismember X (Y::Tail) :- ismember X Tail. |
|
117 |
|
118 |