Datasets:

Modalities:
Text
Languages:
English
Libraries:
Datasets
License:
File size: 12,402 Bytes
4365a98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
(******************************************************************************)
(* FILE          : main.ml                                                    *)
(* DESCRIPTION   : The main functions for the Boyer-Moore-style prover.       *)
(*                                                                            *)
(* READS FILES   : <none>                                                     *)
(* WRITES FILES  : <none>                                                     *)
(*                                                                            *)
(* AUTHOR        : R.J.Boulton                                                *)
(* DATE          : 27th June 1991                                             *)
(*                                                                            *)
(* LAST MODIFIED : R.J.Boulton                                                *)
(* DATE          : 13th October 1992                                          *)
(*                                                                            *)
(* LAST MODIFIED : P. Papapanagiotou (University of Edinburgh)                *)
(* DATE          : July 2009                                                  *)
(******************************************************************************)

(*----------------------------------------------------------------------------*)
(* BOYER_MOORE : conv                                                         *)
(*                                                                            *)
(* Boyer-Moore-style automatic theorem prover.                                *)
(* Given a term "tm", attempts to prove |- tm.                                *)
(*----------------------------------------------------------------------------*)

let BOYER_MOORE_FINAL l tm =
my_gen_terms := [];
counterexamples := 0;
 proof_print_depth := 0;
bm_steps := (0,0);
try  (proof_print_newline
     (FILTERED_WATERFALL
         [taut_heuristic;
          clausal_form_heuristic;
          setify_heuristic;
          subst_heuristic;
          HL_simplify_heuristic l;
          use_equality_heuristic;
          generalize_heuristic_ext;
          irrelevance_heuristic]
         induction_heuristic []
         (tm,false))
 ) with Failure _ -> failwith "BOYER_MOORE";;

let BOYER_MOORE_MESON l tm =
my_gen_terms := [];
counterexamples := 0;
proof_print_depth := 0;
bm_steps := (0,0);
try  (proof_print_newline
     (FILTERED_WATERFALL
         [taut_heuristic;
          clausal_form_heuristic;
          setify_heuristic;
          subst_heuristic;
          HL_simplify_heuristic l;
          meson_heuristic l;
          use_equality_heuristic;
          generalize_heuristic_aderhold;
          irrelevance_heuristic]
         induction_heuristic []
         (tm,false))
 ) with Failure _ -> failwith "BOYER_MOORE";;

let BOYER_MOORE_GEN l tm =
my_gen_terms := [];
counterexamples := 0;
 proof_print_depth := 0;
bm_steps := (0,0);
try  (proof_print_newline
     (FILTERED_WATERFALL
         [taut_heuristic;
          clausal_form_heuristic;
          setify_heuristic;
          subst_heuristic;
          HL_simplify_heuristic l;
          use_equality_heuristic;
          generalize_heuristic_aderhold;
          irrelevance_heuristic]
         induction_heuristic []
         (tm,false))
 ) with Failure _ -> failwith "BOYER_MOORE";;

let BOYER_MOORE_EXT tm =
my_gen_terms := [];
counterexamples := 0;
proof_print_depth := 0;
bm_steps := (0,0);
try  (proof_print_newline
     (FILTERED_WATERFALL
         [taut_heuristic;
          clausal_form_heuristic;
          setify_heuristic;
          subst_heuristic;
          use_equality_heuristic;
          simplify_heuristic;
(*          meson_heuristic; *)
          generalize_heuristic;
          irrelevance_heuristic]
         induction_heuristic []
         (tm,false))
 ) with Failure _ -> failwith "BOYER_MOORE";;


let BOYER_MOORE_RE l tm =
my_gen_terms := [];
counterexamples := 0;
proof_print_depth := 0;
bm_steps := (0,0);
try  (proof_print_newline
     (FILTERED_WATERFALL
         [taut_heuristic;
          clausal_form_heuristic;
          setify_heuristic;
          subst_heuristic;
          use_equality_heuristic;
          HL_simplify_heuristic l;
(*          meson_heuristic; *)
          generalize_heuristic;
          irrelevance_heuristic]
         induction_heuristic []
         (tm,false))
 ) with Failure _ -> failwith "BOYER_MOORE";;

let BOYER_MOORE tm =
counterexamples := 0;
my_gen_terms := [];
 proof_print_depth := 0;
bm_steps := (0,0);
try  (proof_print_newline
     (WATERFALL
         [clausal_form_heuristic;
          subst_heuristic;
          simplify_heuristic;
          use_equality_heuristic;
          generalize_heuristic;
          irrelevance_heuristic]
         induction_heuristic
         (tm,false))
 ) with Failure _ -> failwith "BOYER_MOORE";;

(*----------------------------------------------------------------------------*)
(* BOYER_MOORE_CONV : conv                                                    *)
(*                                                                            *)
(* Boyer-Moore-style automatic theorem prover.                                *)
(* Given a term "tm", attempts to prove |- tm = T.                            *)
(*----------------------------------------------------------------------------*)

let BOYER_MOORE_CONV tm =
try (EQT_INTRO (BOYER_MOORE tm)) with Failure _ -> failwith "BOYER_MOORE_CONV";;

(*----------------------------------------------------------------------------*)
(* HEURISTIC_TAC :                                                            *)
(*    ((term # bool) -> ((term # bool) list # proof)) list -> tactic          *)
(*                                                                            *)
(* Tactic to do automatic proof using a list of heuristics. The tactic will   *)
(* fail if it thinks the goal is not a theorem. Otherwise it will either      *)
(* prove the goal, or return as subgoals the conjectures it couldn't handle.  *)
(*                                                                            *)
(* If the `proof_printing' flag is set to true, the tactic displays each new  *)
(* conjecture it generates, prints blank lines between subconjectures which   *)
(* resulted from a split, and prints a final blank line when it can do no     *)
(* more.                                                                      *)
(*                                                                            *)
(* Given a goal, the tactic constructs an implication from it, so that the    *)
(* hypotheses are made available. It then tries to prove this implication.    *)
(* When it can do no more, the function splits the clauses that it couldn't   *)
(* prove into disjuncts. The last disjunct is assumed to be a conclusion, and *)
(* the rest are taken to be hypotheses. These new goals are returned together *)
(* with a proof of the original goal.                                         *)
(*                                                                            *)
(* The proof takes a list of theorems for the subgoals and discharges the     *)
(* hypotheses so that the theorems are in clausal form. These clauses are     *)
(* then used to prove the implication that was constructed from the original  *)
(* goal. Finally the antecedants of this implication are undischarged to give *)
(* a theorem for the original goal.                                           *)
(*----------------------------------------------------------------------------*)

let HEURISTIC_TAC heuristics (asl,w) =
  proof_print_depth := 0; try
 (let asl = map (concl o snd) asl in
   let negate tm = if (is_neg tm) then (rand tm) else (mk_neg tm)
   and NEG_DISJ_DISCH tm th =
     if (is_neg tm)
     then DISJ_DISCH (rand tm) th
     else CONV_RULE (REWR_CONV IMP_DISJ_THM) (DISCH tm th)
  in  let tm = list_mk_imp (asl,w)
  in  let tree = proof_print_newline
                    (filtered_waterfall (clausal_form_heuristic::heuristics) [] (tm,false))
  in  let tml = map fst (fringe_of_clause_tree tree)
  in  let disjsl = map disj_list tml
  in  let goals = map (fun disjs -> (map negate (butlast disjs),last disjs)) disjsl
  in  let HL_goals = map (fun (asmtms,g) -> (map (fun tm -> ("",ASSUME tm)) asmtms),g) goals
  in  let proof _ thl =
         let thl' = map (fun (th,goal)-> itlist NEG_DISJ_DISCH (fst goal) th)
                           (lcombinep (thl,goals))
         in  funpow (length asl) UNDISCH (fprove_clause_tree tree thl')
  in  (null_meta,HL_goals,proof)
 ) with Failure s -> failwith ("HEURISTIC_TAC: " ^ s);;

(*----------------------------------------------------------------------------*)
(* BOYER_MOORE_TAC : tactic                                                   *)
(*                                                                            *)
(* Tactic to do automatic proof using Boyer & Moore's heuristics. The tactic  *)
(* will fail if it thinks the goal is not a theorem. Otherwise it will either *)
(* prove the goal, or return as subgoals the conjectures it couldn't handle.  *)
(*----------------------------------------------------------------------------*)

let (BOYER_MOORE_TAC:tactic) =
  fun aslw  ->
    try (HEURISTIC_TAC
	   [subst_heuristic;
	    simplify_heuristic;
	    use_equality_heuristic;
	    generalize_heuristic;
	    irrelevance_heuristic;
	    induction_heuristic]
	   aslw
    ) with Failure s -> failwith ("BOYER_MOORE_TAC: " ^ s);;


let (BM_SAFE_TAC:thm list -> tactic) =
  fun l aslw ->
    try (HEURISTIC_TAC
	   [taut_heuristic;
	    setify_heuristic;
	    subst_heuristic;
	    HL_simplify_heuristic l;
(*	    use_equality_heuristic;*)
	    induction_heuristic]
	   aslw
    ) with Failure s -> failwith ("BM_SAFE_TAC: " ^ s);;

let (BMG_TAC:thm list -> tactic) =
  fun l aslw ->
    try (HEURISTIC_TAC
	   [taut_heuristic;
	    setify_heuristic;
	    subst_heuristic;
	    HL_simplify_heuristic l;
	    use_equality_heuristic;
	    generalize_heuristic_aderhold;
	    irrelevance_heuristic;
	    induction_heuristic]
	   aslw
    ) with Failure s -> failwith ("BMG_TAC: " ^ s);;

let (BMF_TAC:thm list -> tactic) =
  fun l aslw ->
    try (HEURISTIC_TAC
	   [taut_heuristic;
	    setify_heuristic;
	    subst_heuristic;
	    HL_simplify_heuristic l;
	    use_equality_heuristic;
	    generalize_heuristic_ext;
	    irrelevance_heuristic;
	    induction_heuristic]
	   aslw
    ) with Failure s -> failwith ("BMF_TAC: " ^ s);;

let (BMF_NOEQ_TAC:thm list -> tactic) =
  fun l aslw ->
    try (HEURISTIC_TAC
	   [taut_heuristic;
	    setify_heuristic;
	    subst_heuristic;
	    HL_simplify_heuristic l;
	    generalize_heuristic_ext;
	    irrelevance_heuristic;
	    induction_heuristic]
	   aslw
    ) with Failure s -> failwith ("BMF_NOEQ_TAC: " ^ s);;


(*----------------------------------------------------------------------------*)
(* BM_SIMPLIFY_TAC : tactic                                                   *)
(*                                                                            *)
(* Tactic to do automatic simplification using Boyer & Moore's heuristics.    *)
(* The tactic will fail if it thinks the goal is not a theorem. Otherwise, it *)
(* will either prove the goal or return the simplified conjectures as         *)
(* subgoals.                                                                  *)
(*----------------------------------------------------------------------------*)

let BM_SIMPLIFY_TAC aslw =
 try (HEURISTIC_TAC [subst_heuristic;simplify_heuristic] aslw
 ) with Failure _ -> failwith "BM_SIMPLIFY_TAC";;

(*----------------------------------------------------------------------------*)
(* BM_INDUCT_TAC : tactic                                                     *)
(*                                                                            *)
(* Tactic which attempts to do a SINGLE induction using Boyer & Moore's       *)
(* heuristics. The cases of the induction are returned as subgoals.           *)
(*----------------------------------------------------------------------------*)

let BM_INDUCT_TAC aslw =
try  (let induct = ref true
  in  let once_induction_heuristic x =
         if !induct then (induct := false; induction_heuristic x) else failwith ""
  in  HEURISTIC_TAC [once_induction_heuristic] aslw
 ) with Failure _ -> failwith "BM_INDUCT_TAC";;