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