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