author | blanchet |
Mon, 03 Feb 2014 13:37:23 +0100 | |
changeset 55282 | d4a033f07800 |
parent 55281 | 765555d6a0b2 |
child 55284 | bd27ac6ad1c3 |
permissions | -rw-r--r-- |
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55194
diff
changeset
|
1 |
(* Title: HOL/Tools/Sledgehammer/sledgehammer_isar_proof.ML |
50263 | 2 |
Author: Jasmin Blanchette, TU Muenchen |
3 |
Author: Steffen Juilf Smolka, TU Muenchen |
|
4 |
||
5 |
Basic data structures for representing and basic methods |
|
6 |
for dealing with Isar proof texts. |
|
7 |
*) |
|
8 |
||
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55194
diff
changeset
|
9 |
signature SLEDGEHAMMER_ISAR_PROOF = |
50259 | 10 |
sig |
51239 | 11 |
type label = string * int |
54816
10d48c2a3e32
made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents:
54767
diff
changeset
|
12 |
type facts = label list * string list (* local and global facts *) |
50268 | 13 |
|
51178 | 14 |
datatype isar_qualifier = Show | Then |
50268 | 15 |
|
55218 | 16 |
datatype proof_method = |
55257 | 17 |
Metis_Method of string option * string option | |
18 |
Simp_Method | |
|
19 |
Simp_Size_Method | |
|
20 |
Auto_Method | |
|
21 |
Fastforce_Method | |
|
22 |
Force_Method | |
|
23 |
Arith_Method | |
|
24 |
Blast_Method | |
|
25 |
Meson_Method | |
|
26 |
Algebra_Method |
|
55218 | 27 |
|
52454 | 28 |
datatype isar_proof = |
54700 | 29 |
Proof of (string * typ) list * (label * term) list * isar_step list |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
30 |
and isar_step = |
50268 | 31 |
Let of term * term | |
55280 | 32 |
Prove of isar_qualifier list * (string * typ) list * label * term * isar_proof list |
33 |
* facts * proof_method list |
|
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52590
diff
changeset
|
34 |
|
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
35 |
val no_label : label |
50268 | 36 |
|
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52590
diff
changeset
|
37 |
val label_ord : label * label -> order |
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51239
diff
changeset
|
38 |
val string_of_label : label -> string |
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52590
diff
changeset
|
39 |
|
55222 | 40 |
val string_of_proof_method : proof_method -> string |
41 |
||
55260 | 42 |
val steps_of_isar_proof : isar_proof -> isar_step list |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
43 |
|
55223
3c593bad6b31
generalized preplaying infrastructure to store various results for various methods
blanchet
parents:
55222
diff
changeset
|
44 |
val label_of_isar_step : isar_step -> label option |
55279 | 45 |
val facts_of_isar_step : isar_step -> facts |
46 |
val proof_methods_of_isar_step : isar_step -> proof_method list |
|
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
47 |
|
54765 | 48 |
val fold_isar_steps : (isar_step -> 'a -> 'a) -> isar_step list -> 'a -> 'a |
55212 | 49 |
val map_isar_steps : (isar_step -> isar_step) -> isar_proof -> isar_proof |
50 |
val add_isar_steps : isar_step list -> int -> int |
|
52454 | 51 |
|
55212 | 52 |
structure Canonical_Label_Tab : TABLE |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
53 |
|
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
54 |
val canonical_label_ord : (label * label) -> order |
55220 | 55 |
|
56 |
val chain_isar_proof : isar_proof -> isar_proof |
|
57 |
val kill_useless_labels_in_isar_proof : isar_proof -> isar_proof |
|
55213 | 58 |
val relabel_isar_proof_canonically : isar_proof -> isar_proof |
55282 | 59 |
val relabel_isar_proof_nicely : isar_proof -> isar_proof |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
60 |
|
55257 | 61 |
val string_of_isar_proof : Proof.context -> int -> int -> |
55244
12e1a5d8ee48
simplified data structure -- eliminated distinction between 'first-class' and 'second-class' proof methods
blanchet
parents:
55223
diff
changeset
|
62 |
(label -> proof_method list -> string) -> isar_proof -> string |
54504 | 63 |
end; |
50259 | 64 |
|
55202
824c48a539c9
renamed many Sledgehammer ML files to clarify structure
blanchet
parents:
55194
diff
changeset
|
65 |
structure Sledgehammer_Isar_Proof : SLEDGEHAMMER_ISAR_PROOF = |
50259 | 66 |
struct |
67 |
||
55211 | 68 |
open ATP_Util |
69 |
open ATP_Proof |
|
70 |
open ATP_Problem_Generate |
|
71 |
open ATP_Proof_Reconstruct |
|
72 |
open Sledgehammer_Util |
|
73 |
open Sledgehammer_Reconstructor |
|
74 |
open Sledgehammer_Isar_Annotate |
|
75 |
||
50259 | 76 |
type label = string * int |
54534 | 77 |
type facts = label list * string list (* local and global facts *) |
50259 | 78 |
|
51178 | 79 |
datatype isar_qualifier = Show | Then |
50259 | 80 |
|
55218 | 81 |
datatype proof_method = |
55257 | 82 |
Metis_Method of string option * string option | |
83 |
Simp_Method | |
|
84 |
Simp_Size_Method | |
|
85 |
Auto_Method | |
|
86 |
Fastforce_Method | |
|
87 |
Force_Method | |
|
88 |
Arith_Method | |
|
89 |
Blast_Method | |
|
90 |
Meson_Method | |
|
91 |
Algebra_Method |
|
55218 | 92 |
|
52454 | 93 |
datatype isar_proof = |
54700 | 94 |
Proof of (string * typ) list * (label * term) list * isar_step list |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
95 |
and isar_step = |
50259 | 96 |
Let of term * term | |
55280 | 97 |
Prove of isar_qualifier list * (string * typ) list * label * term * isar_proof list |
98 |
* facts * proof_method list |
|
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52590
diff
changeset
|
99 |
|
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
100 |
val no_label = ("", ~1) |
50259 | 101 |
|
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52590
diff
changeset
|
102 |
val label_ord = pairself swap #> prod_ord int_ord fast_string_ord |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
103 |
|
51998
f732a674db1b
renamed Sledgehammer functions with 'for' in their names to 'of'
blanchet
parents:
51239
diff
changeset
|
104 |
fun string_of_label (s, num) = s ^ string_of_int num |
50259 | 105 |
|
55222 | 106 |
fun string_of_proof_method meth = |
55218 | 107 |
(case meth of |
55257 | 108 |
Metis_Method (NONE, NONE) => "metis" |
109 |
| Metis_Method (type_enc_opt, lam_trans_opt) => |
|
110 |
"metis (" ^ commas (map_filter I [type_enc_opt, lam_trans_opt]) ^ ")" |
|
55218 | 111 |
| Simp_Method => "simp" |
55257 | 112 |
| Simp_Size_Method => "simp add: size_ne_size_imp_ne" |
55218 | 113 |
| Auto_Method => "auto" |
114 |
| Fastforce_Method => "fastforce" |
|
115 |
| Force_Method => "force" |
|
116 |
| Arith_Method => "arith" |
|
117 |
| Blast_Method => "blast" |
|
55219 | 118 |
| Meson_Method => "meson" |
119 |
| Algebra_Method => "algebra") |
|
55218 | 120 |
|
55260 | 121 |
fun steps_of_isar_proof (Proof (_, _, steps)) = steps |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
122 |
|
55280 | 123 |
fun label_of_isar_step (Prove (_, _, l, _, _, _, _)) = SOME l |
55223
3c593bad6b31
generalized preplaying infrastructure to store various results for various methods
blanchet
parents:
55222
diff
changeset
|
124 |
| label_of_isar_step _ = NONE |
51178 | 125 |
|
55281 | 126 |
fun subproofs_of_isar_step (Prove (_, _, _, _, subs, _, _)) = subs |
127 |
| subproofs_of_isar_step _ = [] |
|
52454 | 128 |
|
55280 | 129 |
fun facts_of_isar_step (Prove (_, _, _, _, _, facts, _)) = facts |
55279 | 130 |
| facts_of_isar_step _ = ([], []) |
131 |
||
55280 | 132 |
fun proof_methods_of_isar_step (Prove (_, _, _, _, _, _, meths)) = meths |
55279 | 133 |
| proof_methods_of_isar_step _ = [] |
51179
0d5f8812856f
split isar_step into isar_step, fix, assms; made isar_proof explicit; register fixed variables in ctxt and auto_fix terms to avoid superfluous annotations
smolkas
parents:
51178
diff
changeset
|
134 |
|
55212 | 135 |
fun fold_isar_step f step = |
55281 | 136 |
fold (steps_of_isar_proof #> fold_isar_steps f) (subproofs_of_isar_step step) #> f step |
55212 | 137 |
and fold_isar_steps f = fold (fold_isar_step f) |
52454 | 138 |
|
54765 | 139 |
fun map_isar_steps f = |
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52590
diff
changeset
|
140 |
let |
55212 | 141 |
fun map_proof (Proof (fix, assms, steps)) = Proof (fix, assms, map map_step steps) |
142 |
and map_step (step as Let _) = f step |
|
55281 | 143 |
| map_step (Prove (qs, xs, l, t, subs, facts, meths)) = |
144 |
f (Prove (qs, xs, l, t, map map_proof subs, facts, meths)) |
|
55212 | 145 |
in map_proof end |
52592
8a25b17e3d79
optimize isar-proofs by trying different proof methods
smolkas
parents:
52590
diff
changeset
|
146 |
|
55212 | 147 |
val add_isar_steps = fold_isar_steps (fn Prove _ => Integer.add 1 | _ => I) |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
148 |
|
55211 | 149 |
(* canonical proof labels: 1, 2, 3, ... in post traversal order *) |
52557 | 150 |
fun canonical_label_ord (((_, i1), (_, i2)) : label * label) = int_ord (i1, i2) |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
151 |
|
55212 | 152 |
structure Canonical_Label_Tab = Table( |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
153 |
type key = label |
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
154 |
val ord = canonical_label_ord) |
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
155 |
|
55220 | 156 |
fun chain_qs_lfs NONE lfs = ([], lfs) |
157 |
| chain_qs_lfs (SOME l0) lfs = |
|
158 |
if member (op =) lfs l0 then ([Then], lfs |> remove (op =) l0) else ([], lfs) |
|
55281 | 159 |
fun chain_isar_step lbl (Prove (qs, xs, l, t, subs, (lfs, gfs), meths)) = |
55220 | 160 |
let val (qs', lfs) = chain_qs_lfs lbl lfs in |
55281 | 161 |
Prove (qs' @ qs, xs, l, t, map chain_isar_proof subs, (lfs, gfs), meths) |
55220 | 162 |
end |
163 |
| chain_isar_step _ step = step |
|
164 |
and chain_isar_steps _ [] = [] |
|
165 |
| chain_isar_steps (prev as SOME _) (i :: is) = |
|
55223
3c593bad6b31
generalized preplaying infrastructure to store various results for various methods
blanchet
parents:
55222
diff
changeset
|
166 |
chain_isar_step prev i :: chain_isar_steps (label_of_isar_step i) is |
3c593bad6b31
generalized preplaying infrastructure to store various results for various methods
blanchet
parents:
55222
diff
changeset
|
167 |
| chain_isar_steps _ (i :: is) = i :: chain_isar_steps (label_of_isar_step i) is |
55220 | 168 |
and chain_isar_proof (Proof (fix, assms, steps)) = |
169 |
Proof (fix, assms, chain_isar_steps (try (List.last #> fst) assms) steps) |
|
170 |
||
171 |
fun kill_useless_labels_in_isar_proof proof = |
|
172 |
let |
|
173 |
val used_ls = |
|
55279 | 174 |
fold_isar_steps (facts_of_isar_step #> fst #> union (op =)) (steps_of_isar_proof proof) [] |
55220 | 175 |
|
176 |
fun kill_label l = if member (op =) used_ls l then l else no_label |
|
177 |
||
55281 | 178 |
fun kill_step (Prove (qs, xs, l, t, subs, facts, meths)) = |
179 |
Prove (qs, xs, kill_label l, t, map kill_proof subs, facts, meths) |
|
55220 | 180 |
| kill_step step = step |
181 |
and kill_proof (Proof (fix, assms, steps)) = |
|
182 |
Proof (fix, map (apfst kill_label) assms, map kill_step steps) |
|
183 |
in |
|
184 |
kill_proof proof |
|
185 |
end |
|
186 |
||
55213 | 187 |
fun relabel_isar_proof_canonically proof = |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
188 |
let |
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
189 |
fun next_label l (next, subst) = |
54534 | 190 |
let val l' = ("", next) in (l', (next + 1, (l, l') :: subst)) end |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
191 |
|
55281 | 192 |
fun relabel_step (Prove (qs, fix, l, t, subs, (lfs, gfs), meths)) (accum as (_, subst)) = |
54534 | 193 |
let |
55281 | 194 |
val lfs' = maps (the_list o AList.lookup (op =) subst) lfs |
195 |
val ((subs', l'), accum') = accum |
|
196 |
|> fold_map relabel_proof subs |
|
197 |
||>> next_label l |
|
54534 | 198 |
in |
55281 | 199 |
(Prove (qs, fix, l', t, subs', (lfs', gfs), meths), accum') |
54534 | 200 |
end |
55281 | 201 |
| relabel_step step accum = (step, accum) |
202 |
and relabel_proof (Proof (fix, assms, steps)) = |
|
203 |
fold_map (fn (l, t) => next_label l #> apfst (rpair t)) assms |
|
204 |
##>> fold_map relabel_step steps |
|
205 |
#>> (fn (assms, steps) => Proof (fix, assms, steps)) |
|
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
206 |
in |
55279 | 207 |
fst (relabel_proof proof (0, [])) |
52556
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
208 |
end |
c8357085217c
completely rewrote SH compress; added two parameters for experimentation/fine grained control
smolkas
parents:
52454
diff
changeset
|
209 |
|
55220 | 210 |
val assume_prefix = "a" |
211 |
val have_prefix = "f" |
|
212 |
||
55282 | 213 |
val relabel_isar_proof_nicely = |
55220 | 214 |
let |
55281 | 215 |
fun next_label depth prefix l (accum as (next, subst)) = |
55220 | 216 |
if l = no_label then |
55281 | 217 |
(l, accum) |
55220 | 218 |
else |
219 |
let val l' = (replicate_string (depth + 1) prefix, next) in |
|
55281 | 220 |
(l', (next + 1, (l, l') :: subst)) |
55220 | 221 |
end |
222 |
||
55281 | 223 |
fun relabel_step depth (Prove (qs, xs, l, t, subs, (lfs, gfs), meths)) (accum as (_, subst)) = |
55220 | 224 |
let |
55281 | 225 |
val lfs' = maps (the_list o AList.lookup (op =) subst) lfs |
226 |
val (l', accum' as (next', subst')) = next_label depth have_prefix l accum |
|
227 |
val subs' = map (relabel_proof subst' (depth + 1)) subs |
|
55220 | 228 |
in |
55281 | 229 |
(Prove (qs, xs, l', t, subs', (lfs', gfs), meths), accum') |
55220 | 230 |
end |
55281 | 231 |
| relabel_step _ step accum = (step, accum) |
55220 | 232 |
and relabel_proof subst depth (Proof (fix, assms, steps)) = |
55281 | 233 |
(1, subst) |
234 |
|> fold_map (fn (l, t) => next_label depth assume_prefix l #> apfst (rpair t)) assms |
|
235 |
||>> fold_map (relabel_step depth) steps |
|
236 |
|> (fn ((assms, steps), _) => Proof (fix, assms, steps)) |
|
55220 | 237 |
in |
238 |
relabel_proof [] 0 |
|
239 |
end |
|
240 |
||
55211 | 241 |
val indent_size = 2 |
242 |
||
55257 | 243 |
fun string_of_isar_proof ctxt i n comment_of proof = |
55211 | 244 |
let |
245 |
(* Make sure only type constraints inserted by the type annotation code are printed. *) |
|
246 |
val ctxt = |
|
247 |
ctxt |> Config.put show_markup false |
|
248 |
|> Config.put Printer.show_type_emphasis false |
|
249 |
|> Config.put show_types false |
|
250 |
|> Config.put show_sorts false |
|
251 |
|> Config.put show_consts false |
|
252 |
||
253 |
val register_fixes = map Free #> fold Variable.auto_fixes |
|
254 |
||
55216 | 255 |
fun add_str s' = apfst (suffix s') |
55211 | 256 |
|
257 |
fun of_indent ind = replicate_string (ind * indent_size) " " |
|
258 |
fun of_moreover ind = of_indent ind ^ "moreover\n" |
|
259 |
fun of_label l = if l = no_label then "" else string_of_label l ^ ": " |
|
260 |
||
261 |
fun of_obtain qs nr = |
|
262 |
(if nr > 1 orelse (nr = 1 andalso member (op =) qs Then) then "ultimately " |
|
263 |
else if nr = 1 orelse member (op =) qs Then then "then " |
|
264 |
else "") ^ "obtain" |
|
265 |
||
266 |
fun of_show_have qs = if member (op =) qs Show then "show" else "have" |
|
267 |
fun of_thus_hence qs = if member (op =) qs Show then "thus" else "hence" |
|
268 |
||
269 |
fun of_have qs nr = |
|
270 |
if nr > 1 orelse (nr = 1 andalso member (op =) qs Then) then "ultimately " ^ of_show_have qs |
|
271 |
else if nr = 1 orelse member (op =) qs Then then of_thus_hence qs |
|
272 |
else of_show_have qs |
|
273 |
||
274 |
fun add_term term (s, ctxt) = |
|
275 |
(s ^ (term |
|
276 |
|> singleton (Syntax.uncheck_terms ctxt) |
|
55213 | 277 |
|> annotate_types_in_term ctxt |
55211 | 278 |
|> with_vanilla_print_mode (Syntax.unparse_term ctxt #> Pretty.string_of) |
279 |
|> simplify_spaces |
|
280 |
|> maybe_quote), |
|
281 |
ctxt |> Variable.auto_fixes term) |
|
282 |
||
283 |
fun with_facts none _ [] [] = none |
|
284 |
| with_facts _ some ls ss = some (space_implode " " (map string_of_label ls @ ss)) |
|
285 |
||
286 |
val using_facts = with_facts "" (enclose "using " " ") |
|
55257 | 287 |
|
288 |
fun maybe_paren s = s |> String.isSubstring " " s ? enclose "(" ")" |
|
289 |
fun by_facts meth ls ss = |
|
290 |
"by " ^ with_facts (maybe_paren meth) (enclose ("(" ^ meth ^ " ") ")") ls ss |
|
291 |
||
292 |
fun is_direct_method (Metis_Method _) = true |
|
293 |
| is_direct_method Meson_Method = true |
|
294 |
| is_direct_method _ = false |
|
55211 | 295 |
|
296 |
(* Local facts are always passed via "using", which affects "meson" and "metis". This is |
|
297 |
arguably stylistically superior, because it emphasises the structure of the proof. It is also |
|
298 |
more robust w.r.t. preplay: Preplay is performed before chaining of local facts with "hence" |
|
299 |
and "thus" is introduced. See also "tac_of_method" in "Sledgehammer_Isar_Preplay". *) |
|
55257 | 300 |
fun of_method ls ss meth = |
55281 | 301 |
let val direct = is_direct_method meth in |
302 |
using_facts ls (if direct then [] else ss) ^ |
|
303 |
by_facts (string_of_proof_method meth) [] (if direct then ss else []) |
|
304 |
end |
|
55211 | 305 |
|
306 |
fun of_free (s, T) = |
|
307 |
maybe_quote s ^ " :: " ^ |
|
308 |
maybe_quote (simplify_spaces (with_vanilla_print_mode (Syntax.string_of_typ ctxt) T)) |
|
309 |
||
310 |
fun add_frees xs (s, ctxt) = |
|
311 |
(s ^ space_implode " and " (map of_free xs), ctxt |> register_fixes xs) |
|
312 |
||
313 |
fun add_fix _ [] = I |
|
55281 | 314 |
| add_fix ind xs = add_str (of_indent ind ^ "fix ") #> add_frees xs #> add_str "\n" |
55211 | 315 |
|
316 |
fun add_assm ind (l, t) = |
|
55281 | 317 |
add_str (of_indent ind ^ "assume " ^ of_label l) #> add_term t #> add_str "\n" |
55211 | 318 |
|
319 |
fun of_subproof ind ctxt proof = |
|
320 |
let |
|
321 |
val ind = ind + 1 |
|
322 |
val s = of_proof ind ctxt proof |
|
323 |
val prefix = "{ " |
|
324 |
val suffix = " }" |
|
325 |
in |
|
326 |
replicate_string (ind * indent_size - size prefix) " " ^ prefix ^ |
|
327 |
String.extract (s, ind * indent_size, SOME (size s - ind * indent_size - 1)) ^ |
|
328 |
suffix ^ "\n" |
|
329 |
end |
|
330 |
and of_subproofs _ _ _ [] = "" |
|
55281 | 331 |
| of_subproofs ind ctxt qs subs = |
55211 | 332 |
(if member (op =) qs Then then of_moreover ind else "") ^ |
55281 | 333 |
space_implode (of_moreover ind) (map (of_subproof ind ctxt) subs) |
334 |
and add_step_pre ind qs subs (s, ctxt) = |
|
335 |
(s ^ of_subproofs ind ctxt qs subs ^ of_indent ind, ctxt) |
|
55211 | 336 |
and add_step ind (Let (t1, t2)) = |
55216 | 337 |
add_str (of_indent ind ^ "let ") |
55281 | 338 |
#> add_term t1 #> add_str " = " #> add_term t2 #> add_str "\n" |
339 |
| add_step ind (Prove (qs, xs, l, t, subs, (ls, ss), meths as meth :: _)) = |
|
340 |
add_step_pre ind qs subs |
|
55211 | 341 |
#> (case xs of |
55281 | 342 |
[] => add_str (of_have qs (length subs) ^ " ") |
343 |
| _ => add_str (of_obtain qs (length subs) ^ " ") #> add_frees xs #> add_str " where ") |
|
55217 | 344 |
#> add_str (of_label l) |
345 |
#> add_term t |
|
346 |
#> add_str (" " ^ |
|
55218 | 347 |
of_method (sort_distinct label_ord ls) (sort_distinct string_ord ss) meth ^ |
55244
12e1a5d8ee48
simplified data structure -- eliminated distinction between 'first-class' and 'second-class' proof methods
blanchet
parents:
55223
diff
changeset
|
348 |
(case comment_of l meths of |
55222 | 349 |
"" => "" |
350 |
| comment => " (* " ^ comment ^ " *)") ^ "\n") |
|
55211 | 351 |
and add_steps ind = fold (add_step ind) |
352 |
and of_proof ind ctxt (Proof (xs, assms, steps)) = |
|
55281 | 353 |
("", ctxt) |
354 |
|> add_fix ind xs |
|
355 |
|> fold (add_assm ind) assms |
|
356 |
|> add_steps ind steps |
|
357 |
|> fst |
|
55211 | 358 |
in |
359 |
(* One-step Metis proofs are pointless; better use the one-liner directly. *) |
|
360 |
(case proof of |
|
361 |
Proof ([], [], []) => "" (* degenerate case: the conjecture is "True" with Z3 *) |
|
55280 | 362 |
| Proof ([], [], [Prove (_, [], _, _, [], _, Metis_Method _ :: _)]) => "" |
55211 | 363 |
| _ => |
364 |
(if i <> 1 then "prefer " ^ string_of_int i ^ "\n" else "") ^ |
|
365 |
of_indent 0 ^ "proof -\n" ^ of_proof 1 ctxt proof ^ |
|
366 |
of_indent 0 ^ (if n <> 1 then "next" else "qed")) |
|
367 |
end |
|
368 |
||
54504 | 369 |
end; |