79 exception SIMPROC_FAIL of string * exn |
79 exception SIMPROC_FAIL of string * exn |
80 val simproc_i: theory -> string -> term list |
80 val simproc_i: theory -> string -> term list |
81 -> (theory -> simpset -> term -> thm option) -> simproc |
81 -> (theory -> simpset -> term -> thm option) -> simproc |
82 val simproc: theory -> string -> string list |
82 val simproc: theory -> string -> string list |
83 -> (theory -> simpset -> term -> thm option) -> simproc |
83 -> (theory -> simpset -> term -> thm option) -> simproc |
84 val revert_bound: simpset -> string -> string option |
|
85 val inherit_bounds: simpset -> simpset -> simpset |
84 val inherit_bounds: simpset -> simpset -> simpset |
86 val rewrite_cterm: bool * bool * bool -> |
85 val rewrite_cterm: bool * bool * bool -> |
87 (simpset -> thm -> thm option) -> simpset -> cterm -> thm |
86 (simpset -> thm -> thm option) -> simpset -> cterm -> thm |
88 val rewrite_aux: (simpset -> thm -> thm option) -> bool -> thm list -> cterm -> thm |
87 val rewrite_aux: (simpset -> thm -> thm option) -> bool -> thm list -> cterm -> thm |
89 val simplify_aux: (simpset -> thm -> thm option) -> bool -> thm list -> thm -> thm |
88 val simplify_aux: (simpset -> thm -> thm option) -> bool -> thm list -> thm -> thm |
249 val used = Term.add_term_names (t, []); |
248 val used = Term.add_term_names (t, []); |
250 val xs = rev (Term.variantlist (rev (map #2 bs), used)); |
249 val xs = rev (Term.variantlist (rev (map #2 bs), used)); |
251 fun subst (((b, T), _), x') = (Free (b, T), Syntax.mark_boundT (x', T)); |
250 fun subst (((b, T), _), x') = (Free (b, T), Syntax.mark_boundT (x', T)); |
252 in Term.subst_atomic (ListPair.map subst (bs, xs)) t end; |
251 in Term.subst_atomic (ListPair.map subst (bs, xs)) t end; |
253 |
252 |
254 fun prtm warn a ss thy t = prnt warn (a ^ "\n" ^ |
253 in |
|
254 |
|
255 fun print_term warn a ss thy t = prnt warn (a ^ "\n" ^ |
255 Sign.string_of_term thy (if ! debug_simp then t else show_bounds ss t)); |
256 Sign.string_of_term thy (if ! debug_simp then t else show_bounds ss t)); |
256 |
|
257 in |
|
258 |
257 |
259 fun debug warn a = if ! debug_simp then prnt warn a else (); |
258 fun debug warn a = if ! debug_simp then prnt warn a else (); |
260 fun trace warn a = if ! trace_simp then prnt warn a else (); |
259 fun trace warn a = if ! trace_simp then prnt warn a else (); |
261 |
260 |
262 fun debug_term warn a ss thy t = if ! debug_simp then prtm warn a ss thy t else (); |
261 fun debug_term warn a ss thy t = if ! debug_simp then print_term warn a ss thy t else (); |
263 fun trace_term warn a ss thy t = if ! trace_simp then prtm warn a ss thy t else (); |
262 fun trace_term warn a ss thy t = if ! trace_simp then print_term warn a ss thy t else (); |
264 |
263 |
265 fun trace_cterm warn a ss ct = |
264 fun trace_cterm warn a ss ct = |
266 if ! trace_simp then prtm warn a ss (Thm.theory_of_cterm ct) (Thm.term_of ct) else (); |
265 if ! trace_simp then print_term warn a ss (Thm.theory_of_cterm ct) (Thm.term_of ct) else (); |
267 |
266 |
268 fun trace_thm a ss th = |
267 fun trace_thm a ss th = |
269 if ! trace_simp then prtm false a ss (Thm.theory_of_thm th) (Thm.full_prop_of th) else (); |
268 if ! trace_simp then print_term false a ss (Thm.theory_of_thm th) (Thm.full_prop_of th) else (); |
270 |
269 |
271 fun trace_named_thm a ss (th, name) = |
270 fun trace_named_thm a ss (th, name) = |
272 if ! trace_simp then |
271 if ! trace_simp then |
273 prtm false (if name = "" then a else a ^ " " ^ quote name ^ ":") ss |
272 print_term false (if name = "" then a else a ^ " " ^ quote name ^ ":") ss |
274 (Thm.theory_of_thm th) (Thm.full_prop_of th) |
273 (Thm.theory_of_thm th) (Thm.full_prop_of th) |
275 else (); |
274 else (); |
276 |
275 |
277 fun warn_thm a ss th = prtm true a ss (Thm.theory_of_thm th) (Thm.full_prop_of th); |
276 fun warn_thm a ss th = print_term true a ss (Thm.theory_of_thm th) (Thm.full_prop_of th); |
278 |
277 |
279 end; |
278 end; |
280 |
279 |
281 |
280 |
282 (* print simpsets *) |
281 (* print simpsets *) |
379 (** simpset operations **) |
378 (** simpset operations **) |
380 |
379 |
381 (* bounds and prems *) |
380 (* bounds and prems *) |
382 |
381 |
383 fun eq_bound (x: string, (y, _)) = x = y; |
382 fun eq_bound (x: string, (y, _)) = x = y; |
384 |
|
385 fun revert_bound (Simpset ({bounds = (_, bs), ...}, _)) = AList.lookup eq_bound bs; |
|
386 |
383 |
387 fun inherit_bounds (Simpset ({bounds, ...}, _)) = |
384 fun inherit_bounds (Simpset ({bounds, ...}, _)) = |
388 map_simpset1 (fn (rules, prems, _) => (rules, prems, bounds)); |
385 map_simpset1 (fn (rules, prems, _) => (rules, prems, bounds)); |
389 |
386 |
390 fun add_bound bound = map_simpset1 (fn (rules, prems, (count, bounds)) => |
387 fun add_bound bound = map_simpset1 (fn (rules, prems, (count, bounds)) => |
1112 use prems of B (if B is again a meta-impl.) to simplify A) |
1109 use prems of B (if B is again a meta-impl.) to simplify A) |
1113 when simplifying A ==> B |
1110 when simplifying A ==> B |
1114 prover: how to solve premises in conditional rewrites and congruences |
1111 prover: how to solve premises in conditional rewrites and congruences |
1115 *) |
1112 *) |
1116 |
1113 |
1117 fun check_bounds ss ct = conditional (! debug_simp) (fn () => |
1114 val debug_bounds = ref false; |
|
1115 |
|
1116 fun check_bounds ss ct = conditional (! debug_bounds) (fn () => |
1118 let |
1117 let |
1119 val Simpset ({bounds = (_, bounds), ...}, _) = ss; |
1118 val Simpset ({bounds = (_, bounds), ...}, _) = ss; |
1120 val bs = fold_aterms (fn Free (x, _) => |
1119 val bs = fold_aterms (fn Free (x, _) => |
1121 if Term.is_bound x andalso not (AList.defined eq_bound bounds x) |
1120 if Term.is_bound x andalso not (AList.defined eq_bound bounds x) |
1122 then insert (op =) x else I |
1121 then insert (op =) x else I |
1123 | _ => I) (term_of ct) []; |
1122 | _ => I) (term_of ct) []; |
1124 in if null bs then () else warning ("Simplifier: term contains loose bounds: " ^ commas bs) end); |
1123 in |
|
1124 if null bs then () |
|
1125 else print_term true ("Simplifier: term contains loose bounds: " ^ commas bs) ss |
|
1126 (Thm.theory_of_cterm ct) (Thm.term_of ct) |
|
1127 end); |
1125 |
1128 |
1126 fun rewrite_cterm mode prover ss ct = |
1129 fun rewrite_cterm mode prover ss ct = |
1127 (inc simp_depth; |
1130 (inc simp_depth; |
1128 if !simp_depth mod 20 = 0 |
1131 if !simp_depth mod 20 = 0 |
1129 then warning ("Simplification depth " ^ string_of_int (!simp_depth)) |
1132 then warning ("Simplification depth " ^ string_of_int (!simp_depth)) |