| author | wenzelm | 
| Wed, 10 May 2023 23:28:15 +0200 | |
| changeset 78030 | ec9840c673c3 | 
| parent 77879 | dd222e2af01a | 
| child 78046 | 78deba4fdf27 | 
| permissions | -rw-r--r-- | 
| 41228 
e1fce873b814
renamed structure MetaSimplifier to raw_Simplifer, to emphasize its meaning;
 wenzelm parents: 
41227diff
changeset | 1 | (* Title: Pure/raw_simplifier.ML | 
| 29269 
5c25a2012975
moved term order operations to structure TermOrd (cf. Pure/term_ord.ML);
 wenzelm parents: 
28839diff
changeset | 2 | Author: Tobias Nipkow and Stefan Berghofer, TU Muenchen | 
| 10413 | 3 | |
| 41228 
e1fce873b814
renamed structure MetaSimplifier to raw_Simplifer, to emphasize its meaning;
 wenzelm parents: 
41227diff
changeset | 4 | Higher-order Simplification. | 
| 10413 | 5 | *) | 
| 6 | ||
| 15006 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 7 | infix 4 | 
| 45620 
f2a587696afb
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45405diff
changeset | 8 | addsimps delsimps addsimprocs delsimprocs | 
| 52037 | 9 | setloop addloop delloop | 
| 45625 
750c5a47400b
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45621diff
changeset | 10 | setSSolver addSSolver setSolver addSolver; | 
| 15006 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 11 | |
| 41228 
e1fce873b814
renamed structure MetaSimplifier to raw_Simplifer, to emphasize its meaning;
 wenzelm parents: 
41227diff
changeset | 12 | signature BASIC_RAW_SIMPLIFIER = | 
| 11672 | 13 | sig | 
| 41227 | 14 | val simp_depth_limit: int Config.T | 
| 15 | val simp_trace_depth_limit: int Config.T | |
| 40878 
7695e4de4d86
renamed trace_simp to simp_trace, and debug_simp to simp_debug;
 wenzelm parents: 
39163diff
changeset | 16 | val simp_debug: bool Config.T | 
| 
7695e4de4d86
renamed trace_simp to simp_trace, and debug_simp to simp_debug;
 wenzelm parents: 
39163diff
changeset | 17 | val simp_trace: bool Config.T | 
| 51590 | 18 | type cong_name = bool * string | 
| 15023 | 19 | type rrule | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
55032diff
changeset | 20 | val mk_rrules: Proof.context -> thm list -> rrule list | 
| 16807 | 21 | val eq_rrule: rrule * rrule -> bool | 
| 15023 | 22 | type proc | 
| 17614 | 23 | type solver | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 24 | val mk_solver: string -> (Proof.context -> int -> tactic) -> solver | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 25 | type simpset | 
| 15023 | 26 | val empty_ss: simpset | 
| 27 | val merge_ss: simpset * simpset -> simpset | |
| 30356 | 28 | val dest_ss: simpset -> | 
| 29 |    {simps: (string * thm) list,
 | |
| 61098 | 30 | procs: (string * term list) list, | 
| 51590 | 31 | congs: (cong_name * thm) list, | 
| 32 | weak_congs: cong_name list, | |
| 30356 | 33 | loopers: string list, | 
| 34 | unsafe_solvers: string list, | |
| 35 | safe_solvers: string list} | |
| 15023 | 36 | type simproc | 
| 22234 | 37 | val eq_simproc: simproc * simproc -> bool | 
| 61144 | 38 | val cert_simproc: theory -> string -> | 
| 62913 | 39 |     {lhss: term list, proc: morphism -> Proof.context -> cterm -> thm option} -> simproc
 | 
| 45290 | 40 | val transform_simproc: morphism -> simproc -> simproc | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 41 | val simpset_of: Proof.context -> simpset | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 42 | val put_simpset: simpset -> Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 43 | val simpset_map: Proof.context -> (Proof.context -> Proof.context) -> simpset -> simpset | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 44 | val map_theory_simpset: (Proof.context -> Proof.context) -> theory -> theory | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 45 | val empty_simpset: Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 46 | val clear_simpset: Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 47 | val addsimps: Proof.context * thm list -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 48 | val delsimps: Proof.context * thm list -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 49 | val addsimprocs: Proof.context * simproc list -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 50 | val delsimprocs: Proof.context * simproc list -> Proof.context | 
| 52037 | 51 | val setloop: Proof.context * (Proof.context -> int -> tactic) -> Proof.context | 
| 52 | val addloop: Proof.context * (string * (Proof.context -> int -> tactic)) -> Proof.context | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 53 | val delloop: Proof.context * string -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 54 | val setSSolver: Proof.context * solver -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 55 | val addSSolver: Proof.context * solver -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 56 | val setSolver: Proof.context * solver -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 57 | val addSolver: Proof.context * solver -> Proof.context | 
| 21708 | 58 | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 59 | val rewrite_rule: Proof.context -> thm list -> thm -> thm | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 60 | val rewrite_goals_rule: Proof.context -> thm list -> thm -> thm | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 61 | val rewrite_goals_tac: Proof.context -> thm list -> tactic | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 62 | val rewrite_goal_tac: Proof.context -> thm list -> int -> tactic | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 63 | val prune_params_tac: Proof.context -> tactic | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 64 | val fold_rule: Proof.context -> thm list -> thm -> thm | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 65 | val fold_goals_tac: Proof.context -> thm list -> tactic | 
| 54883 
dd04a8b654fc
proper context for norm_hhf and derived operations;
 wenzelm parents: 
54742diff
changeset | 66 | val norm_hhf: Proof.context -> thm -> thm | 
| 
dd04a8b654fc
proper context for norm_hhf and derived operations;
 wenzelm parents: 
54742diff
changeset | 67 | val norm_hhf_protect: Proof.context -> thm -> thm | 
| 15006 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 68 | end; | 
| 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 69 | |
| 41228 
e1fce873b814
renamed structure MetaSimplifier to raw_Simplifer, to emphasize its meaning;
 wenzelm parents: 
41227diff
changeset | 70 | signature RAW_SIMPLIFIER = | 
| 10413 | 71 | sig | 
| 41228 
e1fce873b814
renamed structure MetaSimplifier to raw_Simplifer, to emphasize its meaning;
 wenzelm parents: 
41227diff
changeset | 72 | include BASIC_RAW_SIMPLIFIER | 
| 54997 | 73 | exception SIMPLIFIER of string * thm list | 
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 74 | type trace_ops | 
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 75 | val set_trace_ops: trace_ops -> theory -> theory | 
| 71235 | 76 | val subgoal_tac: Proof.context -> int -> tactic | 
| 77 | val loop_tac: Proof.context -> int -> tactic | |
| 78 | val solvers: Proof.context -> solver list * solver list | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 79 | val map_ss: (Proof.context -> Proof.context) -> Context.generic -> Context.generic | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 80 | val prems_of: Proof.context -> thm list | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 81 | val add_simp: thm -> Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 82 | val del_simp: thm -> Proof.context -> Proof.context | 
| 68403 | 83 | val flip_simp: thm -> Proof.context -> Proof.context | 
| 63221 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 84 | val init_simpset: thm list -> Proof.context -> Proof.context | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 85 | val add_eqcong: thm -> Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 86 | val del_eqcong: thm -> Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 87 | val add_cong: thm -> Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 88 | val del_cong: thm -> Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 89 | val mksimps: Proof.context -> thm -> thm list | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 90 | val set_mksimps: (Proof.context -> thm -> thm list) -> Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 91 | val set_mkcong: (Proof.context -> thm -> thm) -> Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 92 | val set_mksym: (Proof.context -> thm -> thm option) -> Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 93 | val set_mkeqTrue: (Proof.context -> thm -> thm option) -> Proof.context -> Proof.context | 
| 70586 | 94 | val set_term_ord: term ord -> Proof.context -> Proof.context | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 95 | val set_subgoaler: (Proof.context -> int -> tactic) -> Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 96 | val solver: Proof.context -> solver -> int -> tactic | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 97 | val default_mk_sym: Proof.context -> thm -> thm option | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 98 | val add_prems: thm list -> Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 99 | val set_reorient: (Proof.context -> term list -> term -> term -> bool) -> | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 100 | Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 101 | val set_solvers: solver list -> Proof.context -> Proof.context | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 102 | val rewrite_cterm: bool * bool * bool -> | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 103 | (Proof.context -> thm -> thm option) -> Proof.context -> conv | 
| 16458 | 104 | val rewrite_term: theory -> thm list -> (term -> term option) list -> term -> term | 
| 15023 | 105 | val rewrite_thm: bool * bool * bool -> | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 106 | (Proof.context -> thm -> thm option) -> Proof.context -> thm -> thm | 
| 46465 | 107 | val generic_rewrite_goal_tac: bool * bool * bool -> | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 108 | (Proof.context -> tactic) -> Proof.context -> int -> tactic | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 109 | val rewrite: Proof.context -> bool -> thm list -> conv | 
| 10413 | 110 | end; | 
| 111 | ||
| 41228 
e1fce873b814
renamed structure MetaSimplifier to raw_Simplifer, to emphasize its meaning;
 wenzelm parents: 
41227diff
changeset | 112 | structure Raw_Simplifier: RAW_SIMPLIFIER = | 
| 10413 | 113 | struct | 
| 114 | ||
| 15023 | 115 | (** datatype simpset **) | 
| 116 | ||
| 51590 | 117 | (* congruence rules *) | 
| 118 | ||
| 119 | type cong_name = bool * string; | |
| 120 | ||
| 121 | fun cong_name (Const (a, _)) = SOME (true, a) | |
| 122 | | cong_name (Free (a, _)) = SOME (false, a) | |
| 123 | | cong_name _ = NONE; | |
| 124 | ||
| 71239 | 125 | structure Congtab = Table(type key = cong_name val ord = prod_ord bool_ord fast_string_ord); | 
| 126 | ||
| 51590 | 127 | |
| 15023 | 128 | (* rewrite rules *) | 
| 10413 | 129 | |
| 20546 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 130 | type rrule = | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 131 |  {thm: thm,         (*the rewrite rule*)
 | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 132 | name: string, (*name of theorem from which rewrite rule was extracted*) | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 133 | lhs: term, (*the left-hand side*) | 
| 58836 | 134 | elhs: cterm, (*the eta-contracted lhs*) | 
| 20546 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 135 | extra: bool, (*extra variables outside of elhs*) | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 136 | fo: bool, (*use first-order matching*) | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 137 | perm: bool}; (*the rewrite rule is permutative*) | 
| 15023 | 138 | |
| 61057 | 139 | fun trim_context_rrule ({thm, name, lhs, elhs, extra, fo, perm}: rrule) =
 | 
| 140 |   {thm = Thm.trim_context thm, name = name, lhs = lhs, elhs = Thm.trim_context_cterm elhs,
 | |
| 141 | extra = extra, fo = fo, perm = perm}; | |
| 142 | ||
| 20546 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 143 | (* | 
| 12603 | 144 | Remarks: | 
| 10413 | 145 | - elhs is used for matching, | 
| 15023 | 146 | lhs only for preservation of bound variable names; | 
| 10413 | 147 | - fo is set iff | 
| 148 | either elhs is first-order (no Var is applied), | |
| 15023 | 149 | in which case fo-matching is complete, | 
| 10413 | 150 | or elhs is not a pattern, | 
| 20546 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 151 | in which case there is nothing better to do; | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 152 | *) | 
| 10413 | 153 | |
| 154 | fun eq_rrule ({thm = thm1, ...}: rrule, {thm = thm2, ...}: rrule) =
 | |
| 22360 
26ead7ed4f4b
moved eq_thm etc. to structure Thm in Pure/more_thm.ML;
 wenzelm parents: 
22254diff
changeset | 155 | Thm.eq_thm_prop (thm1, thm2); | 
| 15023 | 156 | |
| 20546 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 157 | (* FIXME: it seems that the conditions on extra variables are too liberal if | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 158 | prems are nonempty: does solving the prems really guarantee instantiation of | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 159 | all its Vars? Better: a dynamic check each time a rule is applied. | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 160 | *) | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 161 | fun rewrite_rule_extra_vars prems elhs erhs = | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 162 | let | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 163 | val elhss = elhs :: prems; | 
| 74266 | 164 | val tvars = TVars.build (fold TVars.add_tvars elhss); | 
| 165 | val vars = Vars.build (fold Vars.add_vars elhss); | |
| 20546 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 166 | in | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 167 | erhs |> Term.exists_type (Term.exists_subtype | 
| 74266 | 168 | (fn TVar v => not (TVars.defined tvars v) | _ => false)) orelse | 
| 20546 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 169 | erhs |> Term.exists_subterm | 
| 74266 | 170 | (fn Var v => not (Vars.defined vars v) | _ => false) | 
| 20546 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 171 | end; | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 172 | |
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 173 | fun rrule_extra_vars elhs thm = | 
| 59582 | 174 | rewrite_rule_extra_vars [] (Thm.term_of elhs) (Thm.full_prop_of thm); | 
| 20546 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 175 | |
| 15023 | 176 | fun mk_rrule2 {thm, name, lhs, elhs, perm} =
 | 
| 177 | let | |
| 59582 | 178 | val t = Thm.term_of elhs; | 
| 20546 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 179 | val fo = Pattern.first_order t orelse not (Pattern.pattern t); | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 180 | val extra = rrule_extra_vars elhs thm; | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 181 |   in {thm = thm, name = name, lhs = lhs, elhs = elhs, extra = extra, fo = fo, perm = perm} end;
 | 
| 10413 | 182 | |
| 15023 | 183 | (*simple test for looping rewrite rules and stupid orientations*) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 184 | fun default_reorient ctxt prems lhs rhs = | 
| 15023 | 185 | rewrite_rule_extra_vars prems lhs rhs | 
| 186 | orelse | |
| 187 | is_Var (head_of lhs) | |
| 188 | orelse | |
| 16305 | 189 | (* turns t = x around, which causes a headache if x is a local variable - | 
| 190 | usually it is very useful :-( | |
| 191 | is_Free rhs andalso not(is_Free lhs) andalso not(Logic.occs(rhs,lhs)) | |
| 192 | andalso not(exists_subterm is_Var lhs) | |
| 193 | orelse | |
| 194 | *) | |
| 16842 | 195 | exists (fn t => Logic.occs (lhs, t)) (rhs :: prems) | 
| 15023 | 196 | orelse | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 197 | null prems andalso Pattern.matches (Proof_Context.theory_of ctxt) (lhs, rhs) | 
| 10413 | 198 | (*the condition "null prems" is necessary because conditional rewrites | 
| 199 | with extra variables in the conditions may terminate although | |
| 67721 | 200 | the rhs is an instance of the lhs; example: ?m < ?n \<Longrightarrow> f ?n \<equiv> f ?m *) | 
| 15023 | 201 | orelse | 
| 202 | is_Const lhs andalso not (is_Const rhs); | |
| 10413 | 203 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 204 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 205 | (* simplification procedures *) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 206 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 207 | datatype proc = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 208 | Proc of | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 209 |    {name: string,
 | 
| 61098 | 210 | lhs: term, | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 211 | proc: Proof.context -> cterm -> thm option, | 
| 62913 | 212 | stamp: stamp}; | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 213 | |
| 62913 | 214 | fun eq_proc (Proc {stamp = stamp1, ...}, Proc {stamp = stamp2, ...}) = stamp1 = stamp2;
 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 215 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 216 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 217 | (* solvers *) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 218 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 219 | datatype solver = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 220 | Solver of | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 221 |    {name: string,
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 222 | solver: Proof.context -> int -> tactic, | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 223 | id: stamp}; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 224 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 225 | fun mk_solver name solver = Solver {name = name, solver = solver, id = stamp ()};
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 226 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 227 | fun solver_name (Solver {name, ...}) = name;
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 228 | fun solver ctxt (Solver {solver = tac, ...}) = tac ctxt;
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 229 | fun eq_solver (Solver {id = id1, ...}, Solver {id = id2, ...}) = (id1 = id2);
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 230 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 231 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 232 | (* simplification sets *) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 233 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 234 | (*A simpset contains data required during conversion: | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 235 | rules: discrimination net of rewrite rules; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 236 | prems: current premises; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 237 | depth: simp_depth and exceeded flag; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 238 | congs: association list of congruence rules and | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 239 | a list of `weak' congruence constants. | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 240 | A congruence is `weak' if it avoids normalization of some argument. | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 241 | procs: discrimination net of simplification procedures | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 242 | (functions that prove rewrite rules on the fly); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 243 | mk_rews: | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 244 | mk: turn simplification thms into rewrite rules; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 245 | mk_cong: prepare congruence rules; | 
| 67721 | 246 | mk_sym: turn \<equiv> around; | 
| 247 | mk_eq_True: turn P into P \<equiv> True; | |
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 248 | term_ord: for ordered rewriting;*) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 249 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 250 | datatype simpset = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 251 | Simpset of | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 252 |    {rules: rrule Net.net,
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 253 | prems: thm list, | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 254 | depth: int * bool Unsynchronized.ref} * | 
| 71239 | 255 |    {congs: thm Congtab.table * cong_name list,
 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 256 | procs: proc Net.net, | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 257 | mk_rews: | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 258 |      {mk: Proof.context -> thm -> thm list,
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 259 | mk_cong: Proof.context -> thm -> thm, | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 260 | mk_sym: Proof.context -> thm -> thm option, | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 261 | mk_eq_True: Proof.context -> thm -> thm option, | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 262 | reorient: Proof.context -> term list -> term -> term -> bool}, | 
| 70586 | 263 | term_ord: term ord, | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 264 | subgoal_tac: Proof.context -> int -> tactic, | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 265 | loop_tacs: (string * (Proof.context -> int -> tactic)) list, | 
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 266 | solvers: solver list * solver list}; | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 267 | |
| 54728 | 268 | fun internal_ss (Simpset (_, ss2)) = ss2; | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 269 | |
| 55014 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 270 | fun make_ss1 (rules, prems, depth) = {rules = rules, prems = prems, depth = depth};
 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 271 | |
| 55014 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 272 | fun map_ss1 f {rules, prems, depth} = make_ss1 (f (rules, prems, depth));
 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 273 | |
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 274 | fun make_ss2 (congs, procs, mk_rews, term_ord, subgoal_tac, loop_tacs, solvers) = | 
| 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 275 |   {congs = congs, procs = procs, mk_rews = mk_rews, term_ord = term_ord,
 | 
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 276 | subgoal_tac = subgoal_tac, loop_tacs = loop_tacs, solvers = solvers}; | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 277 | |
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 278 | fun map_ss2 f {congs, procs, mk_rews, term_ord, subgoal_tac, loop_tacs, solvers} =
 | 
| 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 279 | make_ss2 (f (congs, procs, mk_rews, term_ord, subgoal_tac, loop_tacs, solvers)); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 280 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 281 | fun make_simpset (args1, args2) = Simpset (make_ss1 args1, make_ss2 args2); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 282 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 283 | fun dest_ss (Simpset ({rules, ...}, {congs, procs, loop_tacs, solvers, ...})) =
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 284 |  {simps = Net.entries rules
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 285 |     |> map (fn {name, thm, ...} => (name, thm)),
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 286 | procs = Net.entries procs | 
| 62913 | 287 |     |> map (fn Proc {name, lhs, stamp, ...} => ((name, lhs), stamp))
 | 
| 288 | |> partition_eq (eq_snd op =) | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 289 | |> map (fn ps => (fst (fst (hd ps)), map (snd o fst) ps)), | 
| 71239 | 290 | congs = congs |> fst |> Congtab.dest, | 
| 291 | weak_congs = congs |> snd, | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 292 | loopers = map fst loop_tacs, | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 293 | unsafe_solvers = map solver_name (#1 solvers), | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 294 | safe_solvers = map solver_name (#2 solvers)}; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 295 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 296 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 297 | (* empty *) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 298 | |
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 299 | fun init_ss depth mk_rews term_ord subgoal_tac solvers = | 
| 55014 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 300 | make_simpset ((Net.empty, [], depth), | 
| 71239 | 301 | ((Congtab.empty, []), Net.empty, mk_rews, term_ord, subgoal_tac, [], solvers)); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 302 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 303 | fun default_mk_sym _ th = SOME (th RS Drule.symmetric_thm); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 304 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 305 | val empty_ss = | 
| 55014 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 306 | init_ss (0, Unsynchronized.ref false) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 307 |     {mk = fn _ => fn th => if can Logic.dest_equals (Thm.concl_of th) then [th] else [],
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 308 | mk_cong = K I, | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 309 | mk_sym = default_mk_sym, | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 310 | mk_eq_True = K (K NONE), | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 311 | reorient = default_reorient} | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 312 | Term_Ord.term_ord (K (K no_tac)) ([], []); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 313 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 314 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 315 | (* merge *) (*NOTE: ignores some fields of 2nd simpset*) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 316 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 317 | fun merge_ss (ss1, ss2) = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 318 | if pointer_eq (ss1, ss2) then ss1 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 319 | else | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 320 | let | 
| 55014 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 321 |       val Simpset ({rules = rules1, prems = prems1, depth = depth1},
 | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 322 |        {congs = (congs1, weak1), procs = procs1, mk_rews, term_ord, subgoal_tac,
 | 
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 323 | loop_tacs = loop_tacs1, solvers = (unsafe_solvers1, solvers1)}) = ss1; | 
| 55014 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 324 |       val Simpset ({rules = rules2, prems = prems2, depth = depth2},
 | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 325 |        {congs = (congs2, weak2), procs = procs2, mk_rews = _, term_ord = _, subgoal_tac = _,
 | 
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 326 | loop_tacs = loop_tacs2, solvers = (unsafe_solvers2, solvers2)}) = ss2; | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 327 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 328 | val rules' = Net.merge eq_rrule (rules1, rules2); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 329 | val prems' = Thm.merge_thms (prems1, prems2); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 330 | val depth' = if #1 depth1 < #1 depth2 then depth2 else depth1; | 
| 71239 | 331 | val congs' = Congtab.merge (K true) (congs1, congs2); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 332 | val weak' = merge (op =) (weak1, weak2); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 333 | val procs' = Net.merge eq_proc (procs1, procs2); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 334 | val loop_tacs' = AList.merge (op =) (K true) (loop_tacs1, loop_tacs2); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 335 | val unsafe_solvers' = merge eq_solver (unsafe_solvers1, unsafe_solvers2); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 336 | val solvers' = merge eq_solver (solvers1, solvers2); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 337 | in | 
| 55014 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 338 | make_simpset ((rules', prems', depth'), ((congs', weak'), procs', | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 339 | mk_rews, term_ord, subgoal_tac, loop_tacs', (unsafe_solvers', solvers'))) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 340 | end; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 341 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 342 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 343 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 344 | (** context data **) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 345 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 346 | structure Simpset = Generic_Data | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 347 | ( | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 348 | type T = simpset; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 349 | val empty = empty_ss; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 350 | val merge = merge_ss; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 351 | ); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 352 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 353 | val simpset_of = Simpset.get o Context.Proof; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 354 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 355 | fun map_simpset f = Context.proof_map (Simpset.map f); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 356 | fun map_simpset1 f = map_simpset (fn Simpset (ss1, ss2) => Simpset (map_ss1 f ss1, ss2)); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 357 | fun map_simpset2 f = map_simpset (fn Simpset (ss1, ss2) => Simpset (ss1, map_ss2 f ss2)); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 358 | |
| 71403 | 359 | fun put_simpset ss = map_simpset (K ss); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 360 | |
| 71403 | 361 | fun simpset_map ctxt f ss = ctxt |> put_simpset ss |> f |> simpset_of; | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 362 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 363 | val empty_simpset = put_simpset empty_ss; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 364 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 365 | fun map_theory_simpset f thy = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 366 | let | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 367 | val ctxt' = f (Proof_Context.init_global thy); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 368 | val thy' = Proof_Context.theory_of ctxt'; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 369 | in Context.theory_map (Simpset.map (K (simpset_of ctxt'))) thy' end; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 370 | |
| 57859 
29e728588163
more careful treatment of context visibility for rule declarations (see also 39d9c7f175e0, e639d91d9073) -- avoid duplicate warnings;
 wenzelm parents: 
56438diff
changeset | 371 | fun map_ss f = Context.mapping (map_theory_simpset (f o Context_Position.not_really)) f; | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 372 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 373 | val clear_simpset = | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 374 |   map_simpset (fn Simpset ({depth, ...}, {mk_rews, term_ord, subgoal_tac, solvers, ...}) =>
 | 
| 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 375 | init_ss depth mk_rews term_ord subgoal_tac solvers); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 376 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 377 | |
| 71235 | 378 | (* accessors for tactis *) | 
| 379 | ||
| 380 | fun subgoal_tac ctxt = (#subgoal_tac o internal_ss o simpset_of) ctxt ctxt; | |
| 381 | ||
| 382 | fun loop_tac ctxt = | |
| 383 | FIRST' (map (fn (_, tac) => tac ctxt) (rev ((#loop_tacs o internal_ss o simpset_of) ctxt))); | |
| 384 | ||
| 385 | val solvers = #solvers o internal_ss o simpset_of | |
| 386 | ||
| 387 | ||
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 388 | (* simp depth *) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 389 | |
| 66934 | 390 | (* | 
| 391 | The simp_depth_limit is meant to abort infinite recursion of the simplifier | |
| 392 | early but should not terminate "normal" executions. | |
| 393 | As of 2017, 25 would suffice; 40 builds in a safety margin. | |
| 394 | *) | |
| 395 | ||
| 69575 | 396 | val simp_depth_limit = Config.declare_int ("simp_depth_limit", \<^here>) (K 40);
 | 
| 397 | val simp_trace_depth_limit = Config.declare_int ("simp_trace_depth_limit", \<^here>) (K 1);
 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 398 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 399 | fun inc_simp_depth ctxt = | 
| 55014 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 400 | ctxt |> map_simpset1 (fn (rules, prems, (depth, exceeded)) => | 
| 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 401 | (rules, prems, | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 402 | (depth + 1, | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 403 | if depth = Config.get ctxt simp_trace_depth_limit | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 404 | then Unsynchronized.ref false else exceeded))); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 405 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 406 | fun simp_depth ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 407 |   let val Simpset ({depth = (depth, _), ...}, _) = simpset_of ctxt
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 408 | in depth end; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 409 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 410 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 411 | (* diagnostics *) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 412 | |
| 54997 | 413 | exception SIMPLIFIER of string * thm list; | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 414 | |
| 69575 | 415 | val simp_debug = Config.declare_bool ("simp_debug", \<^here>) (K false);
 | 
| 416 | val simp_trace = Config.declare_bool ("simp_trace", \<^here>) (K false);
 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 417 | |
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 418 | fun cond_warning ctxt msg = | 
| 57859 
29e728588163
more careful treatment of context visibility for rule declarations (see also 39d9c7f175e0, e639d91d9073) -- avoid duplicate warnings;
 wenzelm parents: 
56438diff
changeset | 419 | if Context_Position.is_really_visible ctxt then warning (msg ()) else (); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 420 | |
| 55031 | 421 | fun cond_tracing' ctxt flag msg = | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 422 | if Config.get ctxt flag then | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 423 | let | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 424 |       val Simpset ({depth = (depth, exceeded), ...}, _) = simpset_of ctxt;
 | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 425 | val depth_limit = Config.get ctxt simp_trace_depth_limit; | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 426 | in | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 427 | if depth > depth_limit then | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 428 | if ! exceeded then () else (tracing "simp_trace_depth_limit exceeded!"; exceeded := true) | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 429 | else (tracing (enclose "[" "]" (string_of_int depth) ^ msg ()); exceeded := false) | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 430 | end | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 431 | else (); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 432 | |
| 55031 | 433 | fun cond_tracing ctxt = cond_tracing' ctxt simp_trace; | 
| 434 | ||
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 435 | fun print_term ctxt s t = | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 436 | s ^ "\n" ^ Syntax.string_of_term ctxt t; | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 437 | |
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 438 | fun print_thm ctxt s (name, th) = | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 439 | print_term ctxt (if name = "" then s else s ^ " " ^ quote name ^ ":") (Thm.full_prop_of th); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 440 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 441 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 442 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 443 | (** simpset operations **) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 444 | |
| 55014 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 445 | (* prems *) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 446 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 447 | fun prems_of ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 448 |   let val Simpset ({prems, ...}, _) = simpset_of ctxt in prems end;
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 449 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 450 | fun add_prems ths = | 
| 55014 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 451 | map_simpset1 (fn (rules, prems, depth) => (rules, ths @ prems, depth)); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 452 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 453 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 454 | (* maintain simp rules *) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 455 | |
| 68403 | 456 | fun del_rrule loud (rrule as {thm, elhs, ...}) ctxt =
 | 
| 55014 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 457 | ctxt |> map_simpset1 (fn (rules, prems, depth) => | 
| 59582 | 458 | (Net.delete_term eq_rrule (Thm.term_of elhs, rrule) rules, prems, depth)) | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 459 | handle Net.DELETE => | 
| 68403 | 460 | (if not loud then () | 
| 461 | else cond_warning ctxt | |
| 462 |             (fn () => print_thm ctxt "Rewrite rule not in simpset:" ("", thm));
 | |
| 463 | ctxt); | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 464 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 465 | fun insert_rrule (rrule as {thm, name, ...}) ctxt =
 | 
| 55031 | 466 | (cond_tracing ctxt (fn () => print_thm ctxt "Adding rewrite rule" (name, thm)); | 
| 55014 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 467 | ctxt |> map_simpset1 (fn (rules, prems, depth) => | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 468 | let | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 469 |       val rrule2 as {elhs, ...} = mk_rrule2 rrule;
 | 
| 61057 | 470 | val rules' = Net.insert_term eq_rrule (Thm.term_of elhs, trim_context_rrule rrule2) rules; | 
| 55014 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 471 | in (rules', prems, depth) end) | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 472 | handle Net.INSERT => | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 473 |     (cond_warning ctxt (fn () => print_thm ctxt "Ignoring duplicate rewrite rule:" ("", thm));
 | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 474 | ctxt)); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 475 | |
| 74266 | 476 | val vars_set = Vars.build o Vars.add_vars; | 
| 74227 | 477 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 478 | local | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 479 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 480 | fun vperm (Var _, Var _) = true | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 481 | | vperm (Abs (_, _, s), Abs (_, _, t)) = vperm (s, t) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 482 | | vperm (t1 $ t2, u1 $ u2) = vperm (t1, u1) andalso vperm (t2, u2) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 483 | | vperm (t, u) = (t = u); | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 484 | |
| 74266 | 485 | fun var_perm (t, u) = vperm (t, u) andalso Vars.eq_set (apply2 vars_set (t, u)); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 486 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 487 | in | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 488 | |
| 10413 | 489 | fun decomp_simp thm = | 
| 15023 | 490 | let | 
| 26626 
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
 wenzelm parents: 
26424diff
changeset | 491 | val prop = Thm.prop_of thm; | 
| 15023 | 492 | val prems = Logic.strip_imp_prems prop; | 
| 493 | val concl = Drule.strip_imp_concl (Thm.cprop_of thm); | |
| 22902 
ac833b4bb7ee
moved some Drule operations to Thm (see more_thm.ML);
 wenzelm parents: 
22892diff
changeset | 494 | val (lhs, rhs) = Thm.dest_equals concl handle TERM _ => | 
| 54997 | 495 |       raise SIMPLIFIER ("Rewrite rule not a meta-equality", [thm]);
 | 
| 20579 | 496 | val elhs = Thm.dest_arg (Thm.cprop_of (Thm.eta_conversion lhs)); | 
| 59582 | 497 | val erhs = Envir.eta_contract (Thm.term_of rhs); | 
| 15023 | 498 | val perm = | 
| 59582 | 499 | var_perm (Thm.term_of elhs, erhs) andalso | 
| 500 | not (Thm.term_of elhs aconv erhs) andalso | |
| 501 | not (is_Var (Thm.term_of elhs)); | |
| 502 | in (prems, Thm.term_of lhs, elhs, Thm.term_of rhs, perm) end; | |
| 10413 | 503 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 504 | end; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 505 | |
| 12783 | 506 | fun decomp_simp' thm = | 
| 52091 | 507 | let val (_, lhs, _, rhs, _) = decomp_simp thm in | 
| 54997 | 508 |     if Thm.nprems_of thm > 0 then raise SIMPLIFIER ("Bad conditional rewrite rule", [thm])
 | 
| 12979 
4c76bce4ce39
decomp_simp': use lhs instead of elhs (preserves more bound variable names);
 wenzelm parents: 
12783diff
changeset | 509 | else (lhs, rhs) | 
| 12783 | 510 | end; | 
| 511 | ||
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 512 | fun mk_eq_True ctxt (thm, name) = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 513 |   let val Simpset (_, {mk_rews = {mk_eq_True, ...}, ...}) = simpset_of ctxt in
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 514 | (case mk_eq_True ctxt thm of | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 515 | NONE => [] | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 516 | | SOME eq_True => | 
| 52091 | 517 | let val (_, lhs, elhs, _, _) = decomp_simp eq_True; | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 518 |         in [{thm = eq_True, name = name, lhs = lhs, elhs = elhs, perm = false}] end)
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 519 | end; | 
| 10413 | 520 | |
| 15023 | 521 | (*create the rewrite rule and possibly also the eq_True variant, | 
| 522 | in case there are extra vars on the rhs*) | |
| 52082 | 523 | fun rrule_eq_True ctxt thm name lhs elhs rhs thm2 = | 
| 15023 | 524 |   let val rrule = {thm = thm, name = name, lhs = lhs, elhs = elhs, perm = false} in
 | 
| 20546 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 525 | if rewrite_rule_extra_vars [] lhs rhs then | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 526 | mk_eq_True ctxt (thm2, name) @ [rrule] | 
| 20546 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 527 | else [rrule] | 
| 10413 | 528 | end; | 
| 529 | ||
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 530 | fun mk_rrule ctxt (thm, name) = | 
| 52091 | 531 | let val (prems, lhs, elhs, rhs, perm) = decomp_simp thm in | 
| 15023 | 532 |     if perm then [{thm = thm, name = name, lhs = lhs, elhs = elhs, perm = true}]
 | 
| 533 | else | |
| 534 | (*weak test for loops*) | |
| 59582 | 535 | if rewrite_rule_extra_vars prems lhs rhs orelse is_Var (Thm.term_of elhs) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 536 | then mk_eq_True ctxt (thm, name) | 
| 52082 | 537 | else rrule_eq_True ctxt thm name lhs elhs rhs thm | 
| 70472 
cf66d2db97fe
more robust and convenient treatment of implicit context;
 wenzelm parents: 
69575diff
changeset | 538 |   end |> map (fn {thm, name, lhs, elhs, perm} =>
 | 
| 
cf66d2db97fe
more robust and convenient treatment of implicit context;
 wenzelm parents: 
69575diff
changeset | 539 |     {thm = Thm.trim_context thm, name = name, lhs = lhs,
 | 
| 
cf66d2db97fe
more robust and convenient treatment of implicit context;
 wenzelm parents: 
69575diff
changeset | 540 | elhs = Thm.trim_context_cterm elhs, perm = perm}); | 
| 10413 | 541 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 542 | fun orient_rrule ctxt (thm, name) = | 
| 18208 | 543 | let | 
| 52091 | 544 | val (prems, lhs, elhs, rhs, perm) = decomp_simp thm; | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 545 |     val Simpset (_, {mk_rews = {reorient, mk_sym, ...}, ...}) = simpset_of ctxt;
 | 
| 18208 | 546 | in | 
| 15023 | 547 |     if perm then [{thm = thm, name = name, lhs = lhs, elhs = elhs, perm = true}]
 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 548 | else if reorient ctxt prems lhs rhs then | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 549 | if reorient ctxt prems rhs lhs | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 550 | then mk_eq_True ctxt (thm, name) | 
| 15023 | 551 | else | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 552 | (case mk_sym ctxt thm of | 
| 18208 | 553 | NONE => [] | 
| 554 | | SOME thm' => | |
| 52091 | 555 | let val (_, lhs', elhs', rhs', _) = decomp_simp thm' | 
| 52082 | 556 | in rrule_eq_True ctxt thm' name lhs' elhs' rhs' thm end) | 
| 557 | else rrule_eq_True ctxt thm name lhs elhs rhs thm | |
| 10413 | 558 | end; | 
| 559 | ||
| 68046 | 560 | fun extract_rews ctxt sym thms = | 
| 561 | let | |
| 562 |     val Simpset (_, {mk_rews = {mk, ...}, ...}) = simpset_of ctxt;
 | |
| 563 | val mk = | |
| 564 | if sym then fn ctxt => fn th => (mk ctxt th) RL [Drule.symmetric_thm] | |
| 69137 
90fce429e1bc
Jenkins: run ocaml_setup
 Lars Hupel <lars.hupel@mytum.de> parents: 
68405diff
changeset | 565 | else mk | 
| 68046 | 566 | in maps (fn thm => map (rpair (Thm.get_name_hint thm)) (mk ctxt thm)) thms | 
| 567 | end; | |
| 10413 | 568 | |
| 54982 | 569 | fun extract_safe_rrules ctxt thm = | 
| 68046 | 570 | maps (orient_rrule ctxt) (extract_rews ctxt false [thm]); | 
| 10413 | 571 | |
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
55032diff
changeset | 572 | fun mk_rrules ctxt thms = | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
55032diff
changeset | 573 | let | 
| 68046 | 574 | val rews = extract_rews ctxt false thms | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
55032diff
changeset | 575 | val raw_rrules = flat (map (mk_rrule ctxt) rews) | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
55032diff
changeset | 576 | in map mk_rrule2 raw_rrules end | 
| 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
55032diff
changeset | 577 | |
| 10413 | 578 | |
| 20028 
b9752164ad92
add/del_simps: warning for inactive simpset (no context);
 wenzelm parents: 
19798diff
changeset | 579 | (* add/del rules explicitly *) | 
| 10413 | 580 | |
| 61090 | 581 | local | 
| 582 | ||
| 68046 | 583 | fun comb_simps ctxt comb mk_rrule sym thms = | 
| 584 | let val rews = extract_rews ctxt sym (map (Thm.transfer' ctxt) thms); | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 585 | in fold (fold comb o mk_rrule) rews ctxt end; | 
| 10413 | 586 | |
| 68405 | 587 | (* | 
| 588 | This code checks if the symetric version of a rule is already in the simpset. | |
| 589 | However, the variable names in the two versions of the rule may differ. | |
| 590 | Thus the current test modulo eq_rrule is too weak to be useful | |
| 591 | and needs to be refined. | |
| 592 | ||
| 593 | fun present ctxt rules (rrule as {thm, elhs, ...}) =
 | |
| 594 | (Net.insert_term eq_rrule (Thm.term_of elhs, trim_context_rrule rrule) rules; | |
| 595 | false) | |
| 596 | handle Net.INSERT => | |
| 597 | (cond_warning ctxt | |
| 598 |        (fn () => print_thm ctxt "Symmetric rewrite rule already in simpset:" ("", thm));
 | |
| 599 | true); | |
| 600 | ||
| 601 | fun sym_present ctxt thms = | |
| 602 | let | |
| 603 | val rews = extract_rews ctxt true (map (Thm.transfer' ctxt) thms); | |
| 604 | val rrules = map mk_rrule2 (flat(map (mk_rrule ctxt) rews)) | |
| 605 |     val Simpset({rules, ...},_) = simpset_of ctxt
 | |
| 606 | in exists (present ctxt rules) rrules end | |
| 607 | *) | |
| 61090 | 608 | in | 
| 609 | ||
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 610 | fun ctxt addsimps thms = | 
| 68046 | 611 | comb_simps ctxt insert_rrule (mk_rrule ctxt) false thms; | 
| 612 | ||
| 613 | fun addsymsimps ctxt thms = | |
| 614 | comb_simps ctxt insert_rrule (mk_rrule ctxt) true thms; | |
| 10413 | 615 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 616 | fun ctxt delsimps thms = | 
| 68403 | 617 | comb_simps ctxt (del_rrule true) (map mk_rrule2 o mk_rrule ctxt) false thms; | 
| 618 | ||
| 619 | fun delsimps_quiet ctxt thms = | |
| 620 | comb_simps ctxt (del_rrule false) (map mk_rrule2 o mk_rrule ctxt) false thms; | |
| 15023 | 621 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 622 | fun add_simp thm ctxt = ctxt addsimps [thm]; | 
| 68405 | 623 | (* | 
| 624 | with check for presence of symmetric version: | |
| 625 | if sym_present ctxt [thm] | |
| 626 |   then (cond_warning ctxt (fn () => print_thm ctxt "Ignoring rewrite rule:" ("", thm)); ctxt)
 | |
| 627 | else ctxt addsimps [thm]; | |
| 628 | *) | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 629 | fun del_simp thm ctxt = ctxt delsimps [thm]; | 
| 68403 | 630 | fun flip_simp thm ctxt = addsymsimps (delsimps_quiet ctxt [thm]) [thm]; | 
| 15023 | 631 | |
| 61090 | 632 | end; | 
| 633 | ||
| 63221 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 634 | fun init_simpset thms ctxt = ctxt | 
| 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 635 | |> Context_Position.set_visible false | 
| 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 636 | |> empty_simpset | 
| 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 637 | |> fold add_simp thms | 
| 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 638 | |> Context_Position.restore_visible ctxt; | 
| 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 639 | |
| 57859 
29e728588163
more careful treatment of context visibility for rule declarations (see also 39d9c7f175e0, e639d91d9073) -- avoid duplicate warnings;
 wenzelm parents: 
56438diff
changeset | 640 | |
| 15023 | 641 | (* congs *) | 
| 10413 | 642 | |
| 15023 | 643 | local | 
| 644 | ||
| 645 | fun is_full_cong_prems [] [] = true | |
| 646 | | is_full_cong_prems [] _ = false | |
| 647 | | is_full_cong_prems (p :: prems) varpairs = | |
| 648 | (case Logic.strip_assums_concl p of | |
| 56245 | 649 |         Const ("Pure.eq", _) $ lhs $ rhs =>
 | 
| 15023 | 650 | let val (x, xs) = strip_comb lhs and (y, ys) = strip_comb rhs in | 
| 651 | is_Var x andalso forall is_Bound xs andalso | |
| 20972 | 652 | not (has_duplicates (op =) xs) andalso xs = ys andalso | 
| 20671 | 653 | member (op =) varpairs (x, y) andalso | 
| 19303 | 654 | is_full_cong_prems prems (remove (op =) (x, y) varpairs) | 
| 15023 | 655 | end | 
| 656 | | _ => false); | |
| 657 | ||
| 658 | fun is_full_cong thm = | |
| 10413 | 659 | let | 
| 43597 | 660 | val prems = Thm.prems_of thm and concl = Thm.concl_of thm; | 
| 15023 | 661 | val (lhs, rhs) = Logic.dest_equals concl; | 
| 662 | val (f, xs) = strip_comb lhs and (g, ys) = strip_comb rhs; | |
| 10413 | 663 | in | 
| 20972 | 664 | f = g andalso not (has_duplicates (op =) (xs @ ys)) andalso length xs = length ys andalso | 
| 15023 | 665 | is_full_cong_prems prems (xs ~~ ys) | 
| 10413 | 666 | end; | 
| 667 | ||
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 668 | fun mk_cong ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 669 |   let val Simpset (_, {mk_rews = {mk_cong = f, ...}, ...}) = simpset_of ctxt
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 670 | in f ctxt end; | 
| 45620 
f2a587696afb
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45405diff
changeset | 671 | |
| 
f2a587696afb
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45405diff
changeset | 672 | in | 
| 
f2a587696afb
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45405diff
changeset | 673 | |
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 674 | fun add_eqcong thm ctxt = ctxt |> map_simpset2 | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 675 | (fn (congs, procs, mk_rews, term_ord, subgoal_tac, loop_tacs, solvers) => | 
| 15023 | 676 | let | 
| 45621 | 677 | val (lhs, _) = Logic.dest_equals (Thm.concl_of thm) | 
| 54997 | 678 |         handle TERM _ => raise SIMPLIFIER ("Congruence not a meta-equality", [thm]);
 | 
| 18929 | 679 | (*val lhs = Envir.eta_contract lhs;*) | 
| 45621 | 680 | val a = the (cong_name (head_of lhs)) handle Option.Option => | 
| 54997 | 681 |         raise SIMPLIFIER ("Congruence must start with a constant or free variable", [thm]);
 | 
| 22221 
8a8aa6114a89
changed cong alist - now using AList operations instead of overwrite_warn
 haftmann parents: 
22008diff
changeset | 682 | val (xs, weak) = congs; | 
| 71239 | 683 | val xs' = Congtab.update (a, Thm.trim_context thm) xs; | 
| 22221 
8a8aa6114a89
changed cong alist - now using AList operations instead of overwrite_warn
 haftmann parents: 
22008diff
changeset | 684 | val weak' = if is_full_cong thm then weak else a :: weak; | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 685 | in ((xs', weak'), procs, mk_rews, term_ord, subgoal_tac, loop_tacs, solvers) end); | 
| 10413 | 686 | |
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 687 | fun del_eqcong thm ctxt = ctxt |> map_simpset2 | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 688 | (fn (congs, procs, mk_rews, term_ord, subgoal_tac, loop_tacs, solvers) => | 
| 15023 | 689 | let | 
| 45621 | 690 | val (lhs, _) = Logic.dest_equals (Thm.concl_of thm) | 
| 54997 | 691 |         handle TERM _ => raise SIMPLIFIER ("Congruence not a meta-equality", [thm]);
 | 
| 18929 | 692 | (*val lhs = Envir.eta_contract lhs;*) | 
| 20057 | 693 | val a = the (cong_name (head_of lhs)) handle Option.Option => | 
| 54997 | 694 |         raise SIMPLIFIER ("Congruence must start with a constant", [thm]);
 | 
| 22221 
8a8aa6114a89
changed cong alist - now using AList operations instead of overwrite_warn
 haftmann parents: 
22008diff
changeset | 695 | val (xs, _) = congs; | 
| 71239 | 696 | val xs' = Congtab.delete_safe a xs; | 
| 697 | val weak' = Congtab.fold (fn (a, th) => if is_full_cong th then I else insert (op =) a) xs' []; | |
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 698 | in ((xs', weak'), procs, mk_rews, term_ord, subgoal_tac, loop_tacs, solvers) end); | 
| 10413 | 699 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 700 | fun add_cong thm ctxt = add_eqcong (mk_cong ctxt thm) ctxt; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 701 | fun del_cong thm ctxt = del_eqcong (mk_cong ctxt thm) ctxt; | 
| 15023 | 702 | |
| 703 | end; | |
| 10413 | 704 | |
| 705 | ||
| 15023 | 706 | (* simprocs *) | 
| 707 | ||
| 22234 | 708 | datatype simproc = | 
| 709 | Simproc of | |
| 710 |     {name: string,
 | |
| 61098 | 711 | lhss: term list, | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 712 | proc: morphism -> Proof.context -> cterm -> thm option, | 
| 62913 | 713 | stamp: stamp}; | 
| 22234 | 714 | |
| 62913 | 715 | fun eq_simproc (Simproc {stamp = stamp1, ...}, Simproc {stamp = stamp2, ...}) = stamp1 = stamp2;
 | 
| 22008 | 716 | |
| 62913 | 717 | fun cert_simproc thy name {lhss, proc} =
 | 
| 718 |   Simproc {name = name, lhss = map (Sign.cert_term thy) lhss, proc = proc, stamp = stamp ()};
 | |
| 61144 | 719 | |
| 62913 | 720 | fun transform_simproc phi (Simproc {name, lhss, proc, stamp}) =
 | 
| 22234 | 721 | Simproc | 
| 722 |    {name = name,
 | |
| 61098 | 723 | lhss = map (Morphism.term phi) lhss, | 
| 22669 | 724 | proc = Morphism.transform phi proc, | 
| 62913 | 725 | stamp = stamp}; | 
| 22234 | 726 | |
| 15023 | 727 | local | 
| 10413 | 728 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 729 | fun add_proc (proc as Proc {name, lhs, ...}) ctxt =
 | 
| 55031 | 730 | (cond_tracing ctxt (fn () => | 
| 61098 | 731 |     print_term ctxt ("Adding simplification procedure " ^ quote name ^ " for") lhs);
 | 
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 732 | ctxt |> map_simpset2 | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 733 | (fn (congs, procs, mk_rews, term_ord, subgoal_tac, loop_tacs, solvers) => | 
| 61098 | 734 | (congs, Net.insert_term eq_proc (lhs, proc) procs, | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 735 | mk_rews, term_ord, subgoal_tac, loop_tacs, solvers)) | 
| 15023 | 736 | handle Net.INSERT => | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 737 | (cond_warning ctxt (fn () => "Ignoring duplicate simplification procedure " ^ quote name); | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 738 | ctxt)); | 
| 10413 | 739 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 740 | fun del_proc (proc as Proc {name, lhs, ...}) ctxt =
 | 
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 741 | ctxt |> map_simpset2 | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 742 | (fn (congs, procs, mk_rews, term_ord, subgoal_tac, loop_tacs, solvers) => | 
| 61098 | 743 | (congs, Net.delete_term eq_proc (lhs, proc) procs, | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 744 | mk_rews, term_ord, subgoal_tac, loop_tacs, solvers)) | 
| 15023 | 745 | handle Net.DELETE => | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 746 | (cond_warning ctxt (fn () => "Simplification procedure " ^ quote name ^ " not in simpset"); | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 747 | ctxt); | 
| 10413 | 748 | |
| 62913 | 749 | fun prep_procs (Simproc {name, lhss, proc, stamp}) =
 | 
| 750 |   lhss |> map (fn lhs => Proc {name = name, lhs = lhs, proc = Morphism.form proc, stamp = stamp});
 | |
| 22234 | 751 | |
| 15023 | 752 | in | 
| 10413 | 753 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 754 | fun ctxt addsimprocs ps = fold (fold add_proc o prep_procs) ps ctxt; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 755 | fun ctxt delsimprocs ps = fold (fold del_proc o prep_procs) ps ctxt; | 
| 10413 | 756 | |
| 15023 | 757 | end; | 
| 10413 | 758 | |
| 759 | ||
| 760 | (* mk_rews *) | |
| 761 | ||
| 15023 | 762 | local | 
| 763 | ||
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 764 | fun map_mk_rews f = | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 765 | map_simpset2 (fn (congs, procs, mk_rews, term_ord, subgoal_tac, loop_tacs, solvers) => | 
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 766 | let | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 767 |       val {mk, mk_cong, mk_sym, mk_eq_True, reorient} = mk_rews;
 | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 768 | val (mk', mk_cong', mk_sym', mk_eq_True', reorient') = | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 769 | f (mk, mk_cong, mk_sym, mk_eq_True, reorient); | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 770 |       val mk_rews' = {mk = mk', mk_cong = mk_cong', mk_sym = mk_sym', mk_eq_True = mk_eq_True',
 | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 771 | reorient = reorient'}; | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 772 | in (congs, procs, mk_rews', term_ord, subgoal_tac, loop_tacs, solvers) end); | 
| 15023 | 773 | |
| 774 | in | |
| 10413 | 775 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 776 | fun mksimps ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 777 |   let val Simpset (_, {mk_rews = {mk, ...}, ...}) = simpset_of ctxt
 | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 778 | in mk ctxt end; | 
| 30318 
3d03190d2864
replaced archaic use of rep_ss by Simplifier.mksimps;
 wenzelm parents: 
29269diff
changeset | 779 | |
| 45625 
750c5a47400b
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45621diff
changeset | 780 | fun set_mksimps mk = map_mk_rews (fn (_, mk_cong, mk_sym, mk_eq_True, reorient) => | 
| 18208 | 781 | (mk, mk_cong, mk_sym, mk_eq_True, reorient)); | 
| 15023 | 782 | |
| 45625 
750c5a47400b
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45621diff
changeset | 783 | fun set_mkcong mk_cong = map_mk_rews (fn (mk, _, mk_sym, mk_eq_True, reorient) => | 
| 18208 | 784 | (mk, mk_cong, mk_sym, mk_eq_True, reorient)); | 
| 10413 | 785 | |
| 45625 
750c5a47400b
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45621diff
changeset | 786 | fun set_mksym mk_sym = map_mk_rews (fn (mk, mk_cong, _, mk_eq_True, reorient) => | 
| 18208 | 787 | (mk, mk_cong, mk_sym, mk_eq_True, reorient)); | 
| 10413 | 788 | |
| 45625 
750c5a47400b
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45621diff
changeset | 789 | fun set_mkeqTrue mk_eq_True = map_mk_rews (fn (mk, mk_cong, mk_sym, _, reorient) => | 
| 18208 | 790 | (mk, mk_cong, mk_sym, mk_eq_True, reorient)); | 
| 791 | ||
| 792 | fun set_reorient reorient = map_mk_rews (fn (mk, mk_cong, mk_sym, mk_eq_True, _) => | |
| 793 | (mk, mk_cong, mk_sym, mk_eq_True, reorient)); | |
| 15023 | 794 | |
| 795 | end; | |
| 796 | ||
| 14242 
ec70653a02bf
Added access to the mk_rews field (and friends).
 skalberg parents: 
14040diff
changeset | 797 | |
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 798 | (* term_ord *) | 
| 10413 | 799 | |
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 800 | fun set_term_ord term_ord = | 
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 801 | map_simpset2 (fn (congs, procs, mk_rews, _, subgoal_tac, loop_tacs, solvers) => | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 802 | (congs, procs, mk_rews, term_ord, subgoal_tac, loop_tacs, solvers)); | 
| 15006 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 803 | |
| 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 804 | |
| 15023 | 805 | (* tactics *) | 
| 15006 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 806 | |
| 45625 
750c5a47400b
modernized some old-style infix operations, which were left over from the time of ML proof scripts;
 wenzelm parents: 
45621diff
changeset | 807 | fun set_subgoaler subgoal_tac = | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 808 | map_simpset2 (fn (congs, procs, mk_rews, term_ord, _, loop_tacs, solvers) => | 
| 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 809 | (congs, procs, mk_rews, term_ord, subgoal_tac, loop_tacs, solvers)); | 
| 15006 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 810 | |
| 52037 | 811 | fun ctxt setloop tac = ctxt |> | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 812 | map_simpset2 (fn (congs, procs, mk_rews, term_ord, subgoal_tac, _, solvers) => | 
| 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 813 |    (congs, procs, mk_rews, term_ord, subgoal_tac, [("", tac)], solvers));
 | 
| 15006 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 814 | |
| 52037 | 815 | fun ctxt addloop (name, tac) = ctxt |> | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 816 | map_simpset2 (fn (congs, procs, mk_rews, term_ord, subgoal_tac, loop_tacs, solvers) => | 
| 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 817 | (congs, procs, mk_rews, term_ord, subgoal_tac, | 
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 818 | AList.update (op =) (name, tac) loop_tacs, solvers)); | 
| 15006 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 819 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 820 | fun ctxt delloop name = ctxt |> | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 821 | map_simpset2 (fn (congs, procs, mk_rews, term_ord, subgoal_tac, loop_tacs, solvers) => | 
| 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 822 | (congs, procs, mk_rews, term_ord, subgoal_tac, | 
| 38834 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 823 | (if AList.defined (op =) loop_tacs name then () | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 824 | else cond_warning ctxt (fn () => "No such looper in simpset: " ^ quote name); | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 825 | AList.delete (op =) name loop_tacs), solvers)); | 
| 15006 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 826 | |
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 827 | fun ctxt setSSolver solver = ctxt |> map_simpset2 | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 828 | (fn (congs, procs, mk_rews, term_ord, subgoal_tac, loop_tacs, (unsafe_solvers, _)) => | 
| 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 829 | (congs, procs, mk_rews, term_ord, subgoal_tac, loop_tacs, (unsafe_solvers, [solver]))); | 
| 15006 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 830 | |
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 831 | fun ctxt addSSolver solver = ctxt |> map_simpset2 (fn (congs, procs, mk_rews, term_ord, | 
| 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 832 | subgoal_tac, loop_tacs, (unsafe_solvers, solvers)) => (congs, procs, mk_rews, term_ord, | 
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 833 | subgoal_tac, loop_tacs, (unsafe_solvers, insert eq_solver solver solvers))); | 
| 15006 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 834 | |
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 835 | fun ctxt setSolver solver = ctxt |> map_simpset2 (fn (congs, procs, mk_rews, term_ord, | 
| 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 836 | subgoal_tac, loop_tacs, (_, solvers)) => (congs, procs, mk_rews, term_ord, | 
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 837 | subgoal_tac, loop_tacs, ([solver], solvers))); | 
| 15006 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 838 | |
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 839 | fun ctxt addSolver solver = ctxt |> map_simpset2 (fn (congs, procs, mk_rews, term_ord, | 
| 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 840 | subgoal_tac, loop_tacs, (unsafe_solvers, solvers)) => (congs, procs, mk_rews, term_ord, | 
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 841 | subgoal_tac, loop_tacs, (insert eq_solver solver unsafe_solvers, solvers))); | 
| 15006 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 842 | |
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 843 | fun set_solvers solvers = map_simpset2 (fn (congs, procs, mk_rews, term_ord, | 
| 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 844 | subgoal_tac, loop_tacs, _) => (congs, procs, mk_rews, term_ord, | 
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 845 | subgoal_tac, loop_tacs, (solvers, solvers))); | 
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 846 | |
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 847 | |
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 848 | (* trace operations *) | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 849 | |
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 850 | type trace_ops = | 
| 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 851 |  {trace_invoke: {depth: int, term: term} -> Proof.context -> Proof.context,
 | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
55032diff
changeset | 852 |   trace_apply: {unconditional: bool, term: term, thm: thm, rrule: rrule} ->
 | 
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 853 | Proof.context -> (Proof.context -> (thm * term) option) -> (thm * term) option}; | 
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 854 | |
| 54731 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 855 | structure Trace_Ops = Theory_Data | 
| 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 856 | ( | 
| 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 857 | type T = trace_ops; | 
| 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 858 | val empty: T = | 
| 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 859 |    {trace_invoke = fn _ => fn ctxt => ctxt,
 | 
| 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 860 | trace_apply = fn _ => fn ctxt => fn cont => cont ctxt}; | 
| 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 861 | fun merge (trace_ops, _) = trace_ops; | 
| 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 862 | ); | 
| 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 863 | |
| 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 864 | val set_trace_ops = Trace_Ops.put; | 
| 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 865 | |
| 
384ac33802b0
clarified Trace_Ops: global theory data avoids init of simpset in Pure.thy, which is important to act as neutral element in merge;
 wenzelm parents: 
54729diff
changeset | 866 | val trace_ops = Trace_Ops.get o Proof_Context.theory_of; | 
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 867 | fun trace_invoke args ctxt = #trace_invoke (trace_ops ctxt) args ctxt; | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 868 | fun trace_apply args ctxt = #trace_apply (trace_ops ctxt) args ctxt; | 
| 15006 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 869 | |
| 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 870 | |
| 
107e4dfd3b96
Merging the meta-simplifier with the Provers-simplifier.  Next step:
 skalberg parents: 
15001diff
changeset | 871 | |
| 10413 | 872 | (** rewriting **) | 
| 873 | ||
| 874 | (* | |
| 875 | Uses conversions, see: | |
| 876 | L C Paulson, A higher-order implementation of rewriting, | |
| 877 | Science of Computer Programming 3 (1983), pages 119-149. | |
| 878 | *) | |
| 879 | ||
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 880 | fun check_conv ctxt msg thm thm' = | 
| 10413 | 881 | let | 
| 36944 | 882 | val thm'' = Thm.transitive thm thm' handle THM _ => | 
| 59690 
46b635624feb
rhs of eqn is only eta- but not beta-eta-contracted; hence the latter is performed explicitly if needed
 nipkow parents: 
59647diff
changeset | 883 | let | 
| 
46b635624feb
rhs of eqn is only eta- but not beta-eta-contracted; hence the latter is performed explicitly if needed
 nipkow parents: 
59647diff
changeset | 884 | val nthm' = | 
| 
46b635624feb
rhs of eqn is only eta- but not beta-eta-contracted; hence the latter is performed explicitly if needed
 nipkow parents: 
59647diff
changeset | 885 | Thm.transitive (Thm.symmetric (Drule.beta_eta_conversion (Thm.lhs_of thm'))) thm' | 
| 
46b635624feb
rhs of eqn is only eta- but not beta-eta-contracted; hence the latter is performed explicitly if needed
 nipkow parents: 
59647diff
changeset | 886 | in Thm.transitive thm nthm' handle THM _ => | 
| 
46b635624feb
rhs of eqn is only eta- but not beta-eta-contracted; hence the latter is performed explicitly if needed
 nipkow parents: 
59647diff
changeset | 887 | let | 
| 
46b635624feb
rhs of eqn is only eta- but not beta-eta-contracted; hence the latter is performed explicitly if needed
 nipkow parents: 
59647diff
changeset | 888 | val nthm = | 
| 
46b635624feb
rhs of eqn is only eta- but not beta-eta-contracted; hence the latter is performed explicitly if needed
 nipkow parents: 
59647diff
changeset | 889 | Thm.transitive thm (Drule.beta_eta_conversion (Thm.rhs_of thm)) | 
| 
46b635624feb
rhs of eqn is only eta- but not beta-eta-contracted; hence the latter is performed explicitly if needed
 nipkow parents: 
59647diff
changeset | 890 | in Thm.transitive nthm nthm' end | 
| 
46b635624feb
rhs of eqn is only eta- but not beta-eta-contracted; hence the latter is performed explicitly if needed
 nipkow parents: 
59647diff
changeset | 891 | end | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 892 | val _ = | 
| 55031 | 893 |       if msg then cond_tracing ctxt (fn () => print_thm ctxt "SUCCEEDED" ("", thm'))
 | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 894 | else (); | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 895 | in SOME thm'' end | 
| 10413 | 896 | handle THM _ => | 
| 26626 
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
 wenzelm parents: 
26424diff
changeset | 897 | let | 
| 
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
 wenzelm parents: 
26424diff
changeset | 898 | val _ $ _ $ prop0 = Thm.prop_of thm; | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 899 | val _ = | 
| 55032 
b49366215417
back to conditional tracing instead of noisy warning (see also 00e849f5b397): these incidents happen occasionally;
 wenzelm parents: 
55031diff
changeset | 900 | cond_tracing ctxt (fn () => | 
| 
b49366215417
back to conditional tracing instead of noisy warning (see also 00e849f5b397): these incidents happen occasionally;
 wenzelm parents: 
55031diff
changeset | 901 |           print_thm ctxt "Proved wrong theorem (bad subgoaler?)" ("", thm') ^ "\n" ^
 | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 902 | print_term ctxt "Should have proved:" prop0); | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 903 | in NONE end; | 
| 10413 | 904 | |
| 905 | ||
| 906 | (* mk_procrule *) | |
| 907 | ||
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 908 | fun mk_procrule ctxt thm = | 
| 70528 
9b3610fe74d6
treat simproc results as atomic -- more compact proof terms;
 wenzelm parents: 
70472diff
changeset | 909 | let | 
| 
9b3610fe74d6
treat simproc results as atomic -- more compact proof terms;
 wenzelm parents: 
70472diff
changeset | 910 | val (prems, lhs, elhs, rhs, _) = decomp_simp thm | 
| 
9b3610fe74d6
treat simproc results as atomic -- more compact proof terms;
 wenzelm parents: 
70472diff
changeset | 911 | val thm' = Thm.close_derivation \<^here> thm; | 
| 
9b3610fe74d6
treat simproc results as atomic -- more compact proof terms;
 wenzelm parents: 
70472diff
changeset | 912 | in | 
| 15023 | 913 | if rewrite_rule_extra_vars prems lhs rhs | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 914 |     then (cond_warning ctxt (fn () => print_thm ctxt "Extra vars on rhs:" ("", thm)); [])
 | 
| 70528 
9b3610fe74d6
treat simproc results as atomic -- more compact proof terms;
 wenzelm parents: 
70472diff
changeset | 915 |     else [mk_rrule2 {thm = thm', name = "", lhs = lhs, elhs = elhs, perm = false}]
 | 
| 10413 | 916 | end; | 
| 917 | ||
| 918 | ||
| 15023 | 919 | (* rewritec: conversion to apply the meta simpset to a term *) | 
| 10413 | 920 | |
| 15023 | 921 | (*Since the rewriting strategy is bottom-up, we avoid re-normalizing already | 
| 922 | normalized terms by carrying around the rhs of the rewrite rule just | |
| 923 | applied. This is called the `skeleton'. It is decomposed in parallel | |
| 924 | with the term. Once a Var is encountered, the corresponding term is | |
| 925 | already in normal form. | |
| 926 | skel0 is a dummy skeleton that is to enforce complete normalization.*) | |
| 927 | ||
| 10413 | 928 | val skel0 = Bound 0; | 
| 929 | ||
| 15023 | 930 | (*Use rhs as skeleton only if the lhs does not contain unnormalized bits. | 
| 931 | The latter may happen iff there are weak congruence rules for constants | |
| 932 | in the lhs.*) | |
| 10413 | 933 | |
| 15023 | 934 | fun uncond_skel ((_, weak), (lhs, rhs)) = | 
| 935 | if null weak then rhs (*optimization*) | |
| 51591 
e4aeb102ad70
amended uncond_skel to observe notion of cong_name properly -- may affect simplification with Free congs;
 wenzelm parents: 
51590diff
changeset | 936 | else if exists_subterm | 
| 
e4aeb102ad70
amended uncond_skel to observe notion of cong_name properly -- may affect simplification with Free congs;
 wenzelm parents: 
51590diff
changeset | 937 | (fn Const (a, _) => member (op =) weak (true, a) | 
| 
e4aeb102ad70
amended uncond_skel to observe notion of cong_name properly -- may affect simplification with Free congs;
 wenzelm parents: 
51590diff
changeset | 938 | | Free (a, _) => member (op =) weak (false, a) | 
| 
e4aeb102ad70
amended uncond_skel to observe notion of cong_name properly -- may affect simplification with Free congs;
 wenzelm parents: 
51590diff
changeset | 939 | | _ => false) lhs then skel0 | 
| 15023 | 940 | else rhs; | 
| 941 | ||
| 942 | (*Behaves like unconditional rule if rhs does not contain vars not in the lhs. | |
| 943 | Otherwise those vars may become instantiated with unnormalized terms | |
| 944 | while the premises are solved.*) | |
| 945 | ||
| 32797 | 946 | fun cond_skel (args as (_, (lhs, rhs))) = | 
| 74266 | 947 | if Vars.subset (vars_set rhs, vars_set lhs) then uncond_skel args | 
| 10413 | 948 | else skel0; | 
| 949 | ||
| 950 | (* | |
| 15023 | 951 | Rewriting -- we try in order: | 
| 10413 | 952 | (1) beta reduction | 
| 953 | (2) unconditional rewrite rules | |
| 954 | (3) conditional rewrite rules | |
| 955 | (4) simplification procedures | |
| 956 | ||
| 957 | IMPORTANT: rewrite rules must not introduce new Vars or TVars! | |
| 958 | *) | |
| 959 | ||
| 52091 | 960 | fun rewritec (prover, maxt) ctxt t = | 
| 10413 | 961 | let | 
| 61057 | 962 | val thy = Proof_Context.theory_of ctxt; | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 963 |     val Simpset ({rules, ...}, {congs, procs, term_ord, ...}) = simpset_of ctxt;
 | 
| 10413 | 964 | val eta_thm = Thm.eta_conversion t; | 
| 22902 
ac833b4bb7ee
moved some Drule operations to Thm (see more_thm.ML);
 wenzelm parents: 
22892diff
changeset | 965 | val eta_t' = Thm.rhs_of eta_thm; | 
| 59582 | 966 | val eta_t = Thm.term_of eta_t'; | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
55032diff
changeset | 967 | fun rew rrule = | 
| 10413 | 968 | let | 
| 61057 | 969 |         val {thm = thm0, name, lhs, elhs = elhs0, extra, fo, perm} = rrule;
 | 
| 970 | val thm = Thm.transfer thy thm0; | |
| 971 | val elhs = Thm.transfer_cterm thy elhs0; | |
| 32797 | 972 | val prop = Thm.prop_of thm; | 
| 20546 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 973 | val (rthm, elhs') = | 
| 
8923deb735ad
rrule: maintain 'extra' field for rule that contain extra vars outside elhs;
 wenzelm parents: 
20330diff
changeset | 974 | if maxt = ~1 orelse not extra then (thm, elhs) | 
| 22902 
ac833b4bb7ee
moved some Drule operations to Thm (see more_thm.ML);
 wenzelm parents: 
22892diff
changeset | 975 | else (Thm.incr_indexes (maxt + 1) thm, Thm.incr_indexes_cterm (maxt + 1) elhs); | 
| 61057 | 976 | |
| 22902 
ac833b4bb7ee
moved some Drule operations to Thm (see more_thm.ML);
 wenzelm parents: 
22892diff
changeset | 977 | val insts = | 
| 
ac833b4bb7ee
moved some Drule operations to Thm (see more_thm.ML);
 wenzelm parents: 
22892diff
changeset | 978 | if fo then Thm.first_order_match (elhs', eta_t') | 
| 
ac833b4bb7ee
moved some Drule operations to Thm (see more_thm.ML);
 wenzelm parents: 
22892diff
changeset | 979 | else Thm.match (elhs', eta_t'); | 
| 10413 | 980 | val thm' = Thm.instantiate insts (Thm.rename_boundvars lhs eta_t rthm); | 
| 14643 | 981 | val prop' = Thm.prop_of thm'; | 
| 74509 | 982 | val unconditional = Logic.no_prems prop'; | 
| 54725 | 983 | val (lhs', rhs') = Logic.dest_equals (Logic.strip_imp_concl prop'); | 
| 55316 
885500f4aa6a
interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
 Lars Hupel <lars.hupel@mytum.de> parents: 
55032diff
changeset | 984 |         val trace_args = {unconditional = unconditional, term = eta_t, thm = thm', rrule = rrule};
 | 
| 10413 | 985 | in | 
| 67561 
f0b11413f1c9
clarified signature: prefer proper order operation;
 wenzelm parents: 
66934diff
changeset | 986 | if perm andalso is_greater_equal (term_ord (rhs', lhs')) | 
| 54725 | 987 | then | 
| 55031 | 988 | (cond_tracing ctxt (fn () => | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 989 | print_thm ctxt "Cannot apply permutative rewrite rule" (name, thm) ^ "\n" ^ | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 990 |             print_thm ctxt "Term does not become smaller:" ("", thm'));
 | 
| 54725 | 991 | NONE) | 
| 992 | else | |
| 55031 | 993 | (cond_tracing ctxt (fn () => | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 994 | print_thm ctxt "Applying instance of rewrite rule" (name, thm)); | 
| 54725 | 995 | if unconditional | 
| 996 | then | |
| 55031 | 997 |            (cond_tracing ctxt (fn () => print_thm ctxt "Rewriting:" ("", thm'));
 | 
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 998 | trace_apply trace_args ctxt (fn ctxt' => | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 999 | let | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1000 | val lr = Logic.dest_equals prop; | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1001 | val SOME thm'' = check_conv ctxt' false eta_thm thm'; | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1002 | in SOME (thm'', uncond_skel (congs, lr)) end)) | 
| 54725 | 1003 | else | 
| 55031 | 1004 |            (cond_tracing ctxt (fn () => print_thm ctxt "Trying to rewrite:" ("", thm'));
 | 
| 54725 | 1005 | if simp_depth ctxt > Config.get ctxt simp_depth_limit | 
| 55031 | 1006 | then (cond_tracing ctxt (fn () => "simp_depth_limit exceeded - giving up"); NONE) | 
| 54725 | 1007 | else | 
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1008 | trace_apply trace_args ctxt (fn ctxt' => | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1009 | (case prover ctxt' thm' of | 
| 55031 | 1010 |                   NONE => (cond_tracing ctxt' (fn () => print_thm ctxt' "FAILED" ("", thm')); NONE)
 | 
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1011 | | SOME thm2 => | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1012 | (case check_conv ctxt' true eta_thm thm2 of | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1013 | NONE => NONE | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1014 | | SOME thm2' => | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1015 | let | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1016 | val concl = Logic.strip_imp_concl prop; | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1017 | val lr = Logic.dest_equals concl; | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1018 | in SOME (thm2', cond_skel (congs, lr)) end))))) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1019 | end; | 
| 10413 | 1020 | |
| 15531 | 1021 | fun rews [] = NONE | 
| 10413 | 1022 | | rews (rrule :: rrules) = | 
| 15531 | 1023 | let val opt = rew rrule handle Pattern.MATCH => NONE | 
| 54725 | 1024 | in (case opt of NONE => rews rrules | some => some) end; | 
| 10413 | 1025 | |
| 38834 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1026 | fun sort_rrules rrs = | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1027 | let | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1028 |         fun is_simple ({thm, ...}: rrule) =
 | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1029 | (case Thm.prop_of thm of | 
| 56245 | 1030 |             Const ("Pure.eq", _) $ _ $ _ => true
 | 
| 38834 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1031 | | _ => false); | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1032 | fun sort [] (re1, re2) = re1 @ re2 | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1033 | | sort (rr :: rrs) (re1, re2) = | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1034 | if is_simple rr | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1035 | then sort rrs (rr :: re1, re2) | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1036 | else sort rrs (re1, rr :: re2); | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1037 | in sort rrs ([], []) end; | 
| 10413 | 1038 | |
| 15531 | 1039 | fun proc_rews [] = NONE | 
| 15023 | 1040 |       | proc_rews (Proc {name, proc, lhs, ...} :: ps) =
 | 
| 61098 | 1041 | if Pattern.matches (Proof_Context.theory_of ctxt) (lhs, Thm.term_of t) then | 
| 55031 | 1042 | (cond_tracing' ctxt simp_debug (fn () => | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 1043 |               print_term ctxt ("Trying procedure " ^ quote name ^ " on:") eta_t);
 | 
| 54725 | 1044 | (case proc ctxt eta_t' of | 
| 55031 | 1045 | NONE => (cond_tracing' ctxt simp_debug (fn () => "FAILED"); proc_rews ps) | 
| 15531 | 1046 | | SOME raw_thm => | 
| 55031 | 1047 | (cond_tracing ctxt (fn () => | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 1048 |                     print_thm ctxt ("Procedure " ^ quote name ^ " produced rewrite rule:")
 | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 1049 |                       ("", raw_thm));
 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1050 | (case rews (mk_procrule ctxt raw_thm) of | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 1051 | NONE => | 
| 55031 | 1052 | (cond_tracing ctxt (fn () => | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 1053 |                         print_term ctxt ("IGNORED result of simproc " ^ quote name ^
 | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 1054 | " -- does not match") (Thm.term_of t)); | 
| 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 1055 | proc_rews ps) | 
| 54725 | 1056 | | some => some)))) | 
| 10413 | 1057 | else proc_rews ps; | 
| 38834 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1058 | in | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1059 | (case eta_t of | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1060 | Abs _ $ _ => SOME (Thm.transitive eta_thm (Thm.beta_conversion false eta_t'), skel0) | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1061 | | _ => | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1062 | (case rews (sort_rrules (Net.match_term rules eta_t)) of | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1063 | NONE => proc_rews (Net.match_term procs eta_t) | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1064 | | some => some)) | 
| 10413 | 1065 | end; | 
| 1066 | ||
| 1067 | ||
| 1068 | (* conversion to apply a congruence rule to a term *) | |
| 1069 | ||
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1070 | fun congc prover ctxt maxt cong t = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1071 | let | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1072 | val rthm = Thm.incr_indexes (maxt + 1) cong; | 
| 59582 | 1073 | val rlhs = fst (Thm.dest_equals (Drule.strip_imp_concl (Thm.cprop_of rthm))); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1074 | val insts = Thm.match (rlhs, t) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1075 | (* Thm.match can raise Pattern.MATCH; | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1076 | is handled when congc is called *) | 
| 59582 | 1077 | val thm' = | 
| 1078 | Thm.instantiate insts (Thm.rename_boundvars (Thm.term_of rlhs) (Thm.term_of t) rthm); | |
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 1079 | val _ = | 
| 55031 | 1080 |       cond_tracing ctxt (fn () => print_thm ctxt "Applying congruence rule:" ("", thm'));
 | 
| 1081 |     fun err (msg, thm) = (cond_tracing ctxt (fn () => print_thm ctxt msg ("", thm)); NONE);
 | |
| 38834 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1082 | in | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1083 | (case prover thm' of | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1084 |       NONE => err ("Congruence proof failed.  Could not prove", thm')
 | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1085 | | SOME thm2 => | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1086 | (case check_conv ctxt true (Drule.beta_eta_conversion t) thm2 of | 
| 15531 | 1087 |           NONE => err ("Congruence proof failed.  Should not have proved", thm2)
 | 
| 1088 | | SOME thm2' => | |
| 59582 | 1089 | if op aconv (apply2 Thm.term_of (Thm.dest_equals (Thm.cprop_of thm2'))) | 
| 38834 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1090 | then NONE else SOME thm2')) | 
| 10413 | 1091 | end; | 
| 1092 | ||
| 60642 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
 wenzelm parents: 
60324diff
changeset | 1093 | val vA = (("A", 0), propT);
 | 
| 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
 wenzelm parents: 
60324diff
changeset | 1094 | val vB = (("B", 0), propT);
 | 
| 
48dd1cefb4ae
simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
 wenzelm parents: 
60324diff
changeset | 1095 | val vC = (("C", 0), propT);
 | 
| 10413 | 1096 | |
| 15531 | 1097 | fun transitive1 NONE NONE = NONE | 
| 1098 | | transitive1 (SOME thm1) NONE = SOME thm1 | |
| 1099 | | transitive1 NONE (SOME thm2) = SOME thm2 | |
| 54725 | 1100 | | transitive1 (SOME thm1) (SOME thm2) = SOME (Thm.transitive thm1 thm2); | 
| 10413 | 1101 | |
| 15531 | 1102 | fun transitive2 thm = transitive1 (SOME thm); | 
| 1103 | fun transitive3 thm = transitive1 thm o SOME; | |
| 13607 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1104 | |
| 52091 | 1105 | fun bottomc ((simprem, useprem, mutsimp), prover, maxidx) = | 
| 10413 | 1106 | let | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1107 | fun botc skel ctxt t = | 
| 54725 | 1108 | if is_Var skel then NONE | 
| 1109 | else | |
| 1110 | (case subc skel ctxt t of | |
| 1111 | some as SOME thm1 => | |
| 1112 | (case rewritec (prover, maxidx) ctxt (Thm.rhs_of thm1) of | |
| 1113 | SOME (thm2, skel2) => | |
| 1114 | transitive2 (Thm.transitive thm1 thm2) | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1115 | (botc skel2 ctxt (Thm.rhs_of thm2)) | 
| 54725 | 1116 | | NONE => some) | 
| 1117 | | NONE => | |
| 1118 | (case rewritec (prover, maxidx) ctxt t of | |
| 1119 | SOME (thm2, skel2) => transitive2 thm2 | |
| 1120 | (botc skel2 ctxt (Thm.rhs_of thm2)) | |
| 1121 | | NONE => NONE)) | |
| 10413 | 1122 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1123 | and try_botc ctxt t = | 
| 54725 | 1124 | (case botc skel0 ctxt t of | 
| 1125 | SOME trec1 => trec1 | |
| 1126 | | NONE => Thm.reflexive t) | |
| 10413 | 1127 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1128 | and subc skel ctxt t0 = | 
| 55014 
a93f496f6c30
general notion of auxiliary bounds within context;
 wenzelm parents: 
55000diff
changeset | 1129 |         let val Simpset (_, {congs, ...}) = simpset_of ctxt in
 | 
| 59582 | 1130 | (case Thm.term_of t0 of | 
| 74525 
c960bfcb91db
discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
 wenzelm parents: 
74518diff
changeset | 1131 | Abs (a, _, _) => | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1132 | let | 
| 74525 
c960bfcb91db
discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
 wenzelm parents: 
74518diff
changeset | 1133 | val ((v, t'), ctxt') = Variable.dest_abs_cterm t0 ctxt; | 
| 
c960bfcb91db
discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
 wenzelm parents: 
74518diff
changeset | 1134 | val skel' = (case skel of Abs (_, _, sk) => sk | _ => skel0); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1135 | in | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1136 | (case botc skel' ctxt' t' of | 
| 74525 
c960bfcb91db
discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
 wenzelm parents: 
74518diff
changeset | 1137 | SOME thm => SOME (Thm.abstract_rule a v thm) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1138 | | NONE => NONE) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1139 | end | 
| 54725 | 1140 | | t $ _ => | 
| 1141 | (case t of | |
| 56245 | 1142 |                 Const ("Pure.imp", _) $ _  => impc t0 ctxt
 | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1143 | | Abs _ => | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1144 | let val thm = Thm.beta_conversion false t0 | 
| 54725 | 1145 | in | 
| 1146 | (case subc skel0 ctxt (Thm.rhs_of thm) of | |
| 1147 | NONE => SOME thm | |
| 1148 | | SOME thm' => SOME (Thm.transitive thm thm')) | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1149 | end | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1150 | | _ => | 
| 54727 | 1151 | let | 
| 1152 | fun appc () = | |
| 1153 | let | |
| 1154 | val (tskel, uskel) = | |
| 1155 | (case skel of | |
| 1156 | tskel $ uskel => (tskel, uskel) | |
| 1157 | | _ => (skel0, skel0)); | |
| 1158 | val (ct, cu) = Thm.dest_comb t0; | |
| 1159 | in | |
| 1160 | (case botc tskel ctxt ct of | |
| 1161 | SOME thm1 => | |
| 1162 | (case botc uskel ctxt cu of | |
| 1163 | SOME thm2 => SOME (Thm.combination thm1 thm2) | |
| 1164 | | NONE => SOME (Thm.combination thm1 (Thm.reflexive cu))) | |
| 1165 | | NONE => | |
| 1166 | (case botc uskel ctxt cu of | |
| 1167 | SOME thm1 => SOME (Thm.combination (Thm.reflexive ct) thm1) | |
| 1168 | | NONE => NONE)) | |
| 1169 | end; | |
| 1170 | val (h, ts) = strip_comb t; | |
| 54725 | 1171 | in | 
| 1172 | (case cong_name h of | |
| 1173 | SOME a => | |
| 71239 | 1174 | (case Congtab.lookup (fst congs) a of | 
| 61095 | 1175 | NONE => appc () | 
| 54725 | 1176 | | SOME cong => | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1177 | (*post processing: some partial applications h t1 ... tj, j <= length ts, | 
| 67721 | 1178 | may be a redex. Example: map (\<lambda>x. x) = (\<lambda>xs. xs) wrt map_cong*) | 
| 54725 | 1179 | (let | 
| 1180 | val thm = congc (prover ctxt) ctxt maxidx cong t0; | |
| 1181 | val t = the_default t0 (Option.map Thm.rhs_of thm); | |
| 1182 | val (cl, cr) = Thm.dest_comb t | |
| 1183 |                               val dVar = Var(("", 0), dummyT)
 | |
| 1184 | val skel = | |
| 1185 | list_comb (h, replicate (length ts) dVar) | |
| 1186 | in | |
| 1187 | (case botc skel ctxt cl of | |
| 1188 | NONE => thm | |
| 1189 | | SOME thm' => | |
| 1190 | transitive3 thm (Thm.combination thm' (Thm.reflexive cr))) | |
| 1191 | end handle Pattern.MATCH => appc ())) | |
| 1192 | | _ => appc ()) | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1193 | end) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1194 | | _ => NONE) | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1195 | end | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1196 | and impc ct ctxt = | 
| 54725 | 1197 | if mutsimp then mut_impc0 [] ct [] [] ctxt | 
| 1198 | else nonmut_impc ct ctxt | |
| 10413 | 1199 | |
| 54984 
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
 wenzelm parents: 
54982diff
changeset | 1200 | and rules_of_prem prem ctxt = | 
| 59582 | 1201 | if maxidx_of_term (Thm.term_of prem) <> ~1 | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 1202 | then | 
| 55031 | 1203 | (cond_tracing ctxt (fn () => | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 1204 | print_term ctxt "Cannot add premise as rewrite rule because it contains (type) unknowns:" | 
| 59582 | 1205 | (Thm.term_of prem)); | 
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 1206 | (([], NONE), ctxt)) | 
| 13607 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1207 | else | 
| 54984 
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
 wenzelm parents: 
54982diff
changeset | 1208 | let val (asm, ctxt') = Thm.assume_hyps prem ctxt | 
| 
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
 wenzelm parents: 
54982diff
changeset | 1209 | in ((extract_safe_rrules ctxt' asm, SOME asm), ctxt') end | 
| 10413 | 1210 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1211 | and add_rrules (rrss, asms) ctxt = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1212 | (fold o fold) insert_rrule rrss ctxt |> add_prems (map_filter I asms) | 
| 10413 | 1213 | |
| 23178 | 1214 | and disch r prem eq = | 
| 13607 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1215 | let | 
| 22902 
ac833b4bb7ee
moved some Drule operations to Thm (see more_thm.ML);
 wenzelm parents: 
22892diff
changeset | 1216 | val (lhs, rhs) = Thm.dest_equals (Thm.cprop_of eq); | 
| 54727 | 1217 | val eq' = | 
| 1218 | Thm.implies_elim | |
| 77879 | 1219 | (Thm.instantiate (TVars.empty, Vars.make3 (vA, prem) (vB, lhs) (vC, rhs)) | 
| 74282 | 1220 | Drule.imp_cong) | 
| 54727 | 1221 | (Thm.implies_intr prem eq); | 
| 54725 | 1222 | in | 
| 1223 | if not r then eq' | |
| 1224 | else | |
| 1225 | let | |
| 1226 | val (prem', concl) = Thm.dest_implies lhs; | |
| 54727 | 1227 | val (prem'', _) = Thm.dest_implies rhs; | 
| 1228 | in | |
| 1229 | Thm.transitive | |
| 1230 | (Thm.transitive | |
| 77879 | 1231 | (Thm.instantiate (TVars.empty, Vars.make3 (vA, prem') (vB, prem) (vC, concl)) | 
| 74282 | 1232 | Drule.swap_prems_eq) | 
| 54727 | 1233 | eq') | 
| 77879 | 1234 | (Thm.instantiate (TVars.empty, Vars.make3 (vA, prem) (vB, prem'') (vC, concl)) | 
| 74282 | 1235 | Drule.swap_prems_eq) | 
| 54725 | 1236 | end | 
| 10413 | 1237 | end | 
| 1238 | ||
| 13607 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1239 | and rebuild [] _ _ _ _ eq = eq | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1240 | | rebuild (prem :: prems) concl (_ :: rrss) (_ :: asms) ctxt eq = | 
| 13607 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1241 | let | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1242 | val ctxt' = add_rrules (rev rrss, rev asms) ctxt; | 
| 13607 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1243 | val concl' = | 
| 22902 
ac833b4bb7ee
moved some Drule operations to Thm (see more_thm.ML);
 wenzelm parents: 
22892diff
changeset | 1244 | Drule.mk_implies (prem, the_default concl (Option.map Thm.rhs_of eq)); | 
| 54727 | 1245 | val dprem = Option.map (disch false prem); | 
| 38834 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1246 | in | 
| 52091 | 1247 | (case rewritec (prover, maxidx) ctxt' concl' of | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1248 | NONE => rebuild prems concl' rrss asms ctxt (dprem eq) | 
| 54727 | 1249 | | SOME (eq', _) => | 
| 1250 | transitive2 (fold (disch false) prems (the (transitive3 (dprem eq) eq'))) | |
| 1251 | (mut_impc0 (rev prems) (Thm.rhs_of eq') (rev rrss) (rev asms) ctxt)) | |
| 13607 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1252 | end | 
| 15023 | 1253 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1254 | and mut_impc0 prems concl rrss asms ctxt = | 
| 13607 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1255 | let | 
| 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1256 | val prems' = strip_imp_prems concl; | 
| 54984 
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
 wenzelm parents: 
54982diff
changeset | 1257 | val ((rrss', asms'), ctxt') = fold_map rules_of_prem prems' ctxt |>> split_list; | 
| 38834 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1258 | in | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1259 | mut_impc (prems @ prems') (strip_imp_concl concl) (rrss @ rrss') | 
| 54984 
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
 wenzelm parents: 
54982diff
changeset | 1260 | (asms @ asms') [] [] [] [] ctxt' ~1 ~1 | 
| 13607 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1261 | end | 
| 15023 | 1262 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1263 | and mut_impc [] concl [] [] prems' rrss' asms' eqns ctxt changed k = | 
| 33245 | 1264 | transitive1 (fold (fn (eq1, prem) => fn eq2 => transitive1 eq1 | 
| 1265 | (Option.map (disch false prem) eq2)) (eqns ~~ prems') NONE) | |
| 13607 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1266 | (if changed > 0 then | 
| 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1267 | mut_impc (rev prems') concl (rev rrss') (rev asms') | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1268 | [] [] [] [] ctxt ~1 changed | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1269 | else rebuild prems' concl rrss' asms' ctxt | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1270 | (botc skel0 (add_rrules (rev rrss', rev asms') ctxt) concl)) | 
| 13607 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1271 | |
| 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1272 | | mut_impc (prem :: prems) concl (rrs :: rrss) (asm :: asms) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1273 | prems' rrss' asms' eqns ctxt changed k = | 
| 54725 | 1274 | (case (if k = 0 then NONE else botc skel0 (add_rrules | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1275 | (rev rrss' @ rrss, rev asms' @ asms) ctxt) prem) of | 
| 15531 | 1276 | NONE => mut_impc prems concl rrss asms (prem :: prems') | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1277 | (rrs :: rrss') (asm :: asms') (NONE :: eqns) ctxt changed | 
| 13607 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1278 | (if k = 0 then 0 else k - 1) | 
| 54725 | 1279 | | SOME eqn => | 
| 13607 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1280 | let | 
| 22902 
ac833b4bb7ee
moved some Drule operations to Thm (see more_thm.ML);
 wenzelm parents: 
22892diff
changeset | 1281 | val prem' = Thm.rhs_of eqn; | 
| 59582 | 1282 | val tprems = map Thm.term_of prems; | 
| 77863 
760515c45864
revert b43ee37926a9 due to problems with AFP/PAPP_Impossibility;
 wenzelm parents: 
77808diff
changeset | 1283 | val i = 1 + fold Integer.max (map (fn p => | 
| 
760515c45864
revert b43ee37926a9 due to problems with AFP/PAPP_Impossibility;
 wenzelm parents: 
77808diff
changeset | 1284 | find_index (fn q => q aconv p) tprems) (Thm.hyps_of eqn)) ~1; | 
| 54984 
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
 wenzelm parents: 
54982diff
changeset | 1285 | val ((rrs', asm'), ctxt') = rules_of_prem prem' ctxt; | 
| 54725 | 1286 | in | 
| 1287 | mut_impc prems concl rrss asms (prem' :: prems') | |
| 1288 | (rrs' :: rrss') (asm' :: asms') | |
| 1289 | (SOME (fold_rev (disch true) | |
| 1290 | (take i prems) | |
| 1291 | (Drule.imp_cong_rule eqn (Thm.reflexive (Drule.list_implies | |
| 1292 | (drop i prems, concl))))) :: eqns) | |
| 54984 
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
 wenzelm parents: 
54982diff
changeset | 1293 | ctxt' (length prems') ~1 | 
| 54725 | 1294 | end) | 
| 13607 
6908230623a3
Completely reimplemented mutual simplification of premises.
 berghofe parents: 
13569diff
changeset | 1295 | |
| 54725 | 1296 | (*legacy code -- only for backwards compatibility*) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1297 | and nonmut_impc ct ctxt = | 
| 38834 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1298 | let | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1299 | val (prem, conc) = Thm.dest_implies ct; | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1300 | val thm1 = if simprem then botc skel0 ctxt prem else NONE; | 
| 38834 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1301 | val prem1 = the_default prem (Option.map Thm.rhs_of thm1); | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1302 | val ctxt1 = | 
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1303 | if not useprem then ctxt | 
| 54984 
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
 wenzelm parents: 
54982diff
changeset | 1304 | else | 
| 
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
 wenzelm parents: 
54982diff
changeset | 1305 | let val ((rrs, asm), ctxt') = rules_of_prem prem1 ctxt | 
| 
da70ab8531f4
more elementary management of declared hyps, below structure Assumption;
 wenzelm parents: 
54982diff
changeset | 1306 | in add_rrules ([rrs], [asm]) ctxt' end; | 
| 38834 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1307 | in | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1308 | (case botc skel0 ctxt1 conc of | 
| 38834 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1309 | NONE => | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1310 | (case thm1 of | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1311 | NONE => NONE | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1312 | | SOME thm1' => SOME (Drule.imp_cong_rule thm1' (Thm.reflexive conc))) | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1313 | | SOME thm2 => | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1314 | let val thm2' = disch false prem1 thm2 in | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1315 | (case thm1 of | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1316 | NONE => SOME thm2' | 
| 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1317 | | SOME thm1' => | 
| 36944 | 1318 | SOME (Thm.transitive (Drule.imp_cong_rule thm1' (Thm.reflexive conc)) thm2')) | 
| 38834 
658fcba35ed7
more careful treatment of context visibility flag wrt. spurious warnings;
 wenzelm parents: 
38715diff
changeset | 1319 | end) | 
| 54725 | 1320 | end; | 
| 10413 | 1321 | |
| 54725 | 1322 | in try_botc end; | 
| 10413 | 1323 | |
| 1324 | ||
| 67721 | 1325 | (* Meta-rewriting: rewrites t to u and returns the theorem t \<equiv> u *) | 
| 10413 | 1326 | |
| 1327 | (* | |
| 1328 | Parameters: | |
| 1329 | mode = (simplify A, | |
| 1330 | use A in simplifying B, | |
| 1331 | use prems of B (if B is again a meta-impl.) to simplify A) | |
| 67721 | 1332 | when simplifying A \<Longrightarrow> B | 
| 10413 | 1333 | prover: how to solve premises in conditional rewrites and congruences | 
| 1334 | *) | |
| 1335 | ||
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1336 | fun rewrite_cterm mode prover raw_ctxt raw_ct = | 
| 17882 
b6e44fc46cf0
added set/addloop' for simpset dependent loopers;
 wenzelm parents: 
17756diff
changeset | 1337 | let | 
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1338 | val thy = Proof_Context.theory_of raw_ctxt; | 
| 52091 | 1339 | |
| 60324 | 1340 | val ct = raw_ct | 
| 1341 | |> Thm.transfer_cterm thy | |
| 1342 | |> Thm.adjust_maxidx_cterm ~1; | |
| 59586 | 1343 | val maxidx = Thm.maxidx_of_cterm ct; | 
| 52091 | 1344 | |
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1345 | val ctxt = | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1346 | raw_ctxt | 
| 71318 
1be996d8bb98
proper proof body context for Simplifier plugins (solvers, loopers, ...) -- avoid crash due to Subgoal.FOCUS (before e58bc223f46c);
 wenzelm parents: 
71239diff
changeset | 1347 | |> Variable.set_body true | 
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1348 | |> Context_Position.set_visible false | 
| 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1349 | |> inc_simp_depth | 
| 59582 | 1350 |       |> (fn ctxt => trace_invoke {depth = simp_depth ctxt, term = Thm.term_of ct} ctxt);
 | 
| 54729 
c5cd7a58cf2d
generic trace operations for main steps of Simplifier;
 wenzelm parents: 
54728diff
changeset | 1351 | |
| 55028 
00e849f5b397
clarified Simplifier diagnostics -- simplified ML;
 wenzelm parents: 
55014diff
changeset | 1352 | val _ = | 
| 55031 | 1353 | cond_tracing ctxt (fn () => | 
| 59582 | 1354 | print_term ctxt "SIMPLIFIER INVOKED ON THE FOLLOWING TERM:" (Thm.term_of ct)); | 
| 70472 
cf66d2db97fe
more robust and convenient treatment of implicit context;
 wenzelm parents: 
69575diff
changeset | 1355 | in | 
| 
cf66d2db97fe
more robust and convenient treatment of implicit context;
 wenzelm parents: 
69575diff
changeset | 1356 | ct | 
| 
cf66d2db97fe
more robust and convenient treatment of implicit context;
 wenzelm parents: 
69575diff
changeset | 1357 | |> bottomc (mode, Option.map (Drule.flexflex_unique (SOME ctxt)) oo prover, maxidx) ctxt | 
| 
cf66d2db97fe
more robust and convenient treatment of implicit context;
 wenzelm parents: 
69575diff
changeset | 1358 | |> Thm.solve_constraints | 
| 
cf66d2db97fe
more robust and convenient treatment of implicit context;
 wenzelm parents: 
69575diff
changeset | 1359 | end; | 
| 10413 | 1360 | |
| 21708 | 1361 | val simple_prover = | 
| 59498 
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
 wenzelm parents: 
59058diff
changeset | 1362 | SINGLE o (fn ctxt => ALLGOALS (resolve_tac ctxt (prems_of ctxt))); | 
| 21708 | 1363 | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 1364 | fun rewrite _ _ [] = Thm.reflexive | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 1365 | | rewrite ctxt full thms = | 
| 63221 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 1366 | rewrite_cterm (full, false, false) simple_prover (init_simpset thms ctxt); | 
| 11672 | 1367 | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 1368 | fun rewrite_rule ctxt = Conv.fconv_rule o rewrite ctxt true; | 
| 21708 | 1369 | |
| 15023 | 1370 | (*simple term rewriting -- no proof*) | 
| 16458 | 1371 | fun rewrite_term thy rules procs = | 
| 17203 | 1372 | Pattern.rewrite_term thy (map decomp_simp' rules) procs; | 
| 15023 | 1373 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1374 | fun rewrite_thm mode prover ctxt = Conv.fconv_rule (rewrite_cterm mode prover ctxt); | 
| 10413 | 1375 | |
| 23536 
60a1672e298e
moved (asm_)rewrite_goal_tac from goal.ML to meta_simplifier.ML (no longer depends on SELECT_GOAL);
 wenzelm parents: 
23221diff
changeset | 1376 | (*Rewrite the subgoals of a proof state (represented by a theorem)*) | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 1377 | fun rewrite_goals_rule ctxt thms th = | 
| 23584 | 1378 | Conv.fconv_rule (Conv.prems_conv ~1 (rewrite_cterm (true, true, true) simple_prover | 
| 63221 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 1379 | (init_simpset thms ctxt))) th; | 
| 10413 | 1380 | |
| 20228 
e0f9e8a6556b
moved Goal.norm_hhf(_protect) to meta_simplifier.ML (pervasive);
 wenzelm parents: 
20197diff
changeset | 1381 | |
| 21708 | 1382 | (** meta-rewriting tactics **) | 
| 1383 | ||
| 28839 
32d498cf7595
eliminated rewrite_tac/fold_tac, which are not well-formed tactics due to change of main conclusion;
 wenzelm parents: 
28620diff
changeset | 1384 | (*Rewrite all subgoals*) | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 1385 | fun rewrite_goals_tac ctxt defs = PRIMITIVE (rewrite_goals_rule ctxt defs); | 
| 21708 | 1386 | |
| 28839 
32d498cf7595
eliminated rewrite_tac/fold_tac, which are not well-formed tactics due to change of main conclusion;
 wenzelm parents: 
28620diff
changeset | 1387 | (*Rewrite one subgoal*) | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1388 | fun generic_rewrite_goal_tac mode prover_tac ctxt i thm = | 
| 25203 
e5b2dd8db7c8
asm_rewrite_goal_tac: avoiding PRIMITIVE lets informative exceptions (from simprocs) get through;
 wenzelm parents: 
24707diff
changeset | 1389 | if 0 < i andalso i <= Thm.nprems_of thm then | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1390 | Seq.single (Conv.gconv_rule (rewrite_cterm mode (SINGLE o prover_tac) ctxt) i thm) | 
| 25203 
e5b2dd8db7c8
asm_rewrite_goal_tac: avoiding PRIMITIVE lets informative exceptions (from simprocs) get through;
 wenzelm parents: 
24707diff
changeset | 1391 | else Seq.empty; | 
| 23536 
60a1672e298e
moved (asm_)rewrite_goal_tac from goal.ML to meta_simplifier.ML (no longer depends on SELECT_GOAL);
 wenzelm parents: 
23221diff
changeset | 1392 | |
| 63221 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 1393 | fun rewrite_goal_tac ctxt thms = | 
| 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 1394 | generic_rewrite_goal_tac (true, false, false) (K no_tac) (init_simpset thms ctxt); | 
| 23536 
60a1672e298e
moved (asm_)rewrite_goal_tac from goal.ML to meta_simplifier.ML (no longer depends on SELECT_GOAL);
 wenzelm parents: 
23221diff
changeset | 1395 | |
| 46707 | 1396 | (*Prunes all redundant parameters from the proof state by rewriting.*) | 
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 1397 | fun prune_params_tac ctxt = rewrite_goals_tac ctxt [Drule.triv_forall_equality]; | 
| 21708 | 1398 | |
| 1399 | ||
| 1400 | (* for folding definitions, handling critical pairs *) | |
| 1401 | ||
| 1402 | (*The depth of nesting in a term*) | |
| 32797 | 1403 | fun term_depth (Abs (_, _, t)) = 1 + term_depth t | 
| 1404 | | term_depth (f $ t) = 1 + Int.max (term_depth f, term_depth t) | |
| 21708 | 1405 | | term_depth _ = 0; | 
| 1406 | ||
| 59582 | 1407 | val lhs_of_thm = #1 o Logic.dest_equals o Thm.prop_of; | 
| 21708 | 1408 | |
| 67721 | 1409 | (*folding should handle critical pairs! E.g. K \<equiv> Inl 0, S \<equiv> Inr (Inl 0) | 
| 21708 | 1410 | Returns longest lhs first to avoid folding its subexpressions.*) | 
| 1411 | fun sort_lhs_depths defs = | |
| 1412 | let val keylist = AList.make (term_depth o lhs_of_thm) defs | |
| 1413 | val keys = sort_distinct (rev_order o int_ord) (map #2 keylist) | |
| 1414 | in map (AList.find (op =) keylist) keys end; | |
| 1415 | ||
| 36944 | 1416 | val rev_defs = sort_lhs_depths o map Thm.symmetric; | 
| 21708 | 1417 | |
| 54742 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 1418 | fun fold_rule ctxt defs = fold (rewrite_rule ctxt) (rev_defs defs); | 
| 
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
 wenzelm parents: 
54731diff
changeset | 1419 | fun fold_goals_tac ctxt defs = EVERY (map (rewrite_goals_tac ctxt) (rev_defs defs)); | 
| 21708 | 1420 | |
| 1421 | ||
| 67721 | 1422 | (* HHF normal form: \<And> before \<Longrightarrow>, outermost \<And> generalized *) | 
| 20228 
e0f9e8a6556b
moved Goal.norm_hhf(_protect) to meta_simplifier.ML (pervasive);
 wenzelm parents: 
20197diff
changeset | 1423 | |
| 
e0f9e8a6556b
moved Goal.norm_hhf(_protect) to meta_simplifier.ML (pervasive);
 wenzelm parents: 
20197diff
changeset | 1424 | local | 
| 
e0f9e8a6556b
moved Goal.norm_hhf(_protect) to meta_simplifier.ML (pervasive);
 wenzelm parents: 
20197diff
changeset | 1425 | |
| 71177 | 1426 | fun gen_norm_hhf ss ctxt0 th0 = | 
| 1427 | let | |
| 1428 | val (ctxt, th) = Thm.join_transfer_context (ctxt0, th0); | |
| 1429 | val th' = | |
| 1430 | if Drule.is_norm_hhf (Thm.prop_of th) then th | |
| 1431 | else | |
| 1432 | Conv.fconv_rule (rewrite_cterm (true, false, false) (K (K NONE)) (put_simpset ss ctxt)) th; | |
| 1433 | in th' |> Thm.adjust_maxidx_thm ~1 |> Variable.gen_all ctxt end; | |
| 20228 
e0f9e8a6556b
moved Goal.norm_hhf(_protect) to meta_simplifier.ML (pervasive);
 wenzelm parents: 
20197diff
changeset | 1434 | |
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1435 | val hhf_ss = | 
| 63221 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 1436 | Context.the_local_context () | 
| 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 1437 | |> init_simpset Drule.norm_hhf_eqs | 
| 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 1438 | |> simpset_of; | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1439 | |
| 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1440 | val hhf_protect_ss = | 
| 63221 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 1441 | Context.the_local_context () | 
| 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 1442 | |> init_simpset Drule.norm_hhf_eqs | 
| 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 1443 | |> add_eqcong Drule.protect_cong | 
| 
7d43fbbaba28
avoid warnings on duplicate rules in the given list;
 wenzelm parents: 
62913diff
changeset | 1444 | |> simpset_of; | 
| 20228 
e0f9e8a6556b
moved Goal.norm_hhf(_protect) to meta_simplifier.ML (pervasive);
 wenzelm parents: 
20197diff
changeset | 1445 | |
| 
e0f9e8a6556b
moved Goal.norm_hhf(_protect) to meta_simplifier.ML (pervasive);
 wenzelm parents: 
20197diff
changeset | 1446 | in | 
| 
e0f9e8a6556b
moved Goal.norm_hhf(_protect) to meta_simplifier.ML (pervasive);
 wenzelm parents: 
20197diff
changeset | 1447 | |
| 26424 | 1448 | val norm_hhf = gen_norm_hhf hhf_ss; | 
| 51717 
9e7d1c139569
simplifier uses proper Proof.context instead of historic type simpset;
 wenzelm parents: 
51611diff
changeset | 1449 | val norm_hhf_protect = gen_norm_hhf hhf_protect_ss; | 
| 20228 
e0f9e8a6556b
moved Goal.norm_hhf(_protect) to meta_simplifier.ML (pervasive);
 wenzelm parents: 
20197diff
changeset | 1450 | |
| 
e0f9e8a6556b
moved Goal.norm_hhf(_protect) to meta_simplifier.ML (pervasive);
 wenzelm parents: 
20197diff
changeset | 1451 | end; | 
| 
e0f9e8a6556b
moved Goal.norm_hhf(_protect) to meta_simplifier.ML (pervasive);
 wenzelm parents: 
20197diff
changeset | 1452 | |
| 10413 | 1453 | end; | 
| 1454 | ||
| 41228 
e1fce873b814
renamed structure MetaSimplifier to raw_Simplifer, to emphasize its meaning;
 wenzelm parents: 
41227diff
changeset | 1455 | structure Basic_Meta_Simplifier: BASIC_RAW_SIMPLIFIER = Raw_Simplifier; | 
| 32738 | 1456 | open Basic_Meta_Simplifier; |