summaryrefslogtreecommitdiff
path: root/examples/systemS/ProofEng.gf
blob: 612e228c8c2d3bdfab9c38aa1969ddd144105f76 (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
--# -path=.:prelude

concrete ProofEng of Proof = FormulaSymb ** open Prelude, Precedence in {

  flags startcat=Text ; unlexer=text ; lexer = text ;

  lincat
    Text, Proof = {s : Str} ; 
    [Formula] = {s : Str ; isnil : Bool} ;

  lin
    Start prems concl proof = {
      s = ifNotNil (\p -> "Suppose" ++ p ++ ".") prems ++
          ["We will show that"] ++ useTop concl ++ "." ++
          proof.s
      } ; 

    Hypo = {
      s = new ++ ["But this holds trivially ."]
      } ;

    Implic prems concl proof = {
      s = new ++ ["It is enough to"] ++
          ifNotNil (\p -> "assume" ++ p ++ "and") prems ++
          "show" ++ concl.s ++ 
          "." ++
          proof.s ;
      } ;

    RedAbs form proof = 
      let neg = useTop (prefixR 4 "~" form) in {
      s = new ++ ["To that end , we will assume"] ++ 
          neg ++
          ["and show"] ++ "_|_" ++ 
          "." ++
          new ++ ["So let us assume that"] ++
          neg ++ 
          "." ++
          proof.s
      } ;

    ExFalso form = {
      s = new ++ ["Hence we get"] ++ 
          useTop form ++ ["as desired"] ++ 
          "." 
      } ;

    ConjSplit a b c proof = {
      s = new ++ ["So by splitting we get"] ++ 
          useTop a ++ "," ++ useTop b ++
          toProve c ++
          "." ++ 
          proof.s
      } ;

    ModPon prems concl proof = {
      s = new ++ ["Then , by Modus ponens , we get"] ++ prems.s ++
          toProve concl ++
          "." ++ 
          proof.s
      } ;

    Forget prems concl proof = {
      s = new ++ ["In particular we get"] ++ prems.s ++
          toProve concl ++
          "." ++ 
          proof.s
      } ;

--

    DeMorgan1 = \form, concl, proof -> {
      s = new ++ ["Then , by the first de Morgan's law , we get"] ++ useTop form ++
          toProve concl ++
          "." ++ 
          proof.s
      } ;

    DeMorgan2 = \form, concl, proof -> {
      s = new ++ ["Then , by the second de Morgan's law , we get"] ++ useTop form ++
          toProve concl ++
          "." ++ 
          proof.s
      } ;

    ImplicNeg forms concl proof = {
      s = new ++ ["By implication negation , we get"] ++ forms.s ++
          toProve concl ++
          "." ++ 
          proof.s
      } ;

    NegRewrite form forms proof = 
      let 
        neg  = useTop (prefixR 4 "~" form) ;
        impl = useTop (infixR 1 "->" form (constant "_|_")) ;
      in {
      s = new ++ ["Thus , by rewriting"] ++ 
          neg ++
          ifNotNil (\p -> ["we may assume"] ++ p ++ "and") forms ++ 
          "show" ++ impl ++ 
          "." ++
          proof.s
      } ;

--

    BaseFormula = {
      s = [] ; 
      isnil = True
      } ;

    ConsFormula f fs = {
      s = useTop f ++ ifNotNil (\p -> "," ++ p) fs ; 
      isnil = False
      } ;
    
  oper
    ifNotNil : (Str -> Str) -> {s : Str ; isnil : Bool} -> Str = \cons,prems ->
      case prems.isnil of {
         True  => prems.s ;
         False => cons prems.s
         } ;

    new = variants {"&-" ; []} ; -- unlexing and parsing, respectively

    toProve : PrecExp -> Str = \c -> 
      variants {
        [] ;                      -- for generation
        ["to prove"] ++ useTop c  -- for parsing
        } ;

}