| author | haftmann | 
| Wed, 18 Feb 2009 19:18:32 +0100 | |
| changeset 29970 | cbf46080ea3a | 
| parent 29606 | fedb8be05f24 | 
| child 30336 | efd1bec4630a | 
| permissions | -rw-r--r-- | 
| 16014 | 1 | (* Title: Pure/simplifier.ML | 
| 2 | Author: Tobias Nipkow and Markus Wenzel, TU Muenchen | |
| 3 | ||
| 4 | Generic simplifier, suitable for most logics (see also | |
| 5 | meta_simplifier.ML for the actual meta-level rewriting engine). | |
| 6 | *) | |
| 7 | ||
| 8 | signature BASIC_SIMPLIFIER = | |
| 9 | sig | |
| 10 | include BASIC_META_SIMPLIFIER | |
| 17883 
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
 wenzelm parents: 
17723diff
changeset | 11 | val change_simpset: (simpset -> simpset) -> unit | 
| 16014 | 12 | val simpset_of: theory -> simpset | 
| 17883 
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
 wenzelm parents: 
17723diff
changeset | 13 | val simpset: unit -> simpset | 
| 16014 | 14 | val SIMPSET: (simpset -> tactic) -> tactic | 
| 15 | val SIMPSET': (simpset -> 'a -> tactic) -> 'a -> tactic | |
| 16 | val Addsimps: thm list -> unit | |
| 17 | val Delsimps: thm list -> unit | |
| 18 | val Addsimprocs: simproc list -> unit | |
| 19 | val Delsimprocs: simproc list -> unit | |
| 20 | val Addcongs: thm list -> unit | |
| 21 | val Delcongs: thm list -> unit | |
| 22 | val local_simpset_of: Proof.context -> simpset | |
| 17967 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 23 | val generic_simp_tac: bool -> bool * bool * bool -> simpset -> int -> tactic | 
| 16014 | 24 | val safe_asm_full_simp_tac: simpset -> int -> tactic | 
| 25 | val simp_tac: simpset -> int -> tactic | |
| 26 | val asm_simp_tac: simpset -> int -> tactic | |
| 27 | val full_simp_tac: simpset -> int -> tactic | |
| 28 | val asm_lr_simp_tac: simpset -> int -> tactic | |
| 29 | val asm_full_simp_tac: simpset -> int -> tactic | |
| 30 | val Simp_tac: int -> tactic | |
| 31 | val Asm_simp_tac: int -> tactic | |
| 32 | val Full_simp_tac: int -> tactic | |
| 33 | val Asm_lr_simp_tac: int -> tactic | |
| 34 | val Asm_full_simp_tac: int -> tactic | |
| 35 | val simplify: simpset -> thm -> thm | |
| 36 | val asm_simplify: simpset -> thm -> thm | |
| 37 | val full_simplify: simpset -> thm -> thm | |
| 38 | val asm_lr_simplify: simpset -> thm -> thm | |
| 39 | val asm_full_simplify: simpset -> thm -> thm | |
| 40 | end; | |
| 41 | ||
| 42 | signature SIMPLIFIER = | |
| 43 | sig | |
| 44 | include BASIC_SIMPLIFIER | |
| 17004 | 45 | val clear_ss: simpset -> simpset | 
| 17723 | 46 | val debug_bounds: bool ref | 
| 17883 
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
 wenzelm parents: 
17723diff
changeset | 47 | val inherit_context: simpset -> simpset -> simpset | 
| 17898 | 48 | val the_context: simpset -> Proof.context | 
| 49 | val context: Proof.context -> simpset -> simpset | |
| 50 | val theory_context: theory -> simpset -> simpset | |
| 16458 | 51 | val simproc_i: theory -> string -> term list | 
| 52 | -> (theory -> simpset -> term -> thm option) -> simproc | |
| 53 | val simproc: theory -> string -> string list | |
| 54 | -> (theory -> simpset -> term -> thm option) -> simproc | |
| 23598 | 55 | val rewrite: simpset -> conv | 
| 56 | val asm_rewrite: simpset -> conv | |
| 57 | val full_rewrite: simpset -> conv | |
| 58 | val asm_lr_rewrite: simpset -> conv | |
| 59 | val asm_full_rewrite: simpset -> conv | |
| 22379 | 60 | val get_ss: Context.generic -> simpset | 
| 61 | val map_ss: (simpset -> simpset) -> Context.generic -> Context.generic | |
| 18728 | 62 | val attrib: (simpset * thm list -> simpset) -> attribute | 
| 63 | val simp_add: attribute | |
| 64 | val simp_del: attribute | |
| 65 | val cong_add: attribute | |
| 66 | val cong_del: attribute | |
| 26497 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 67 | val map_simpset: (simpset -> simpset) -> theory -> theory | 
| 24024 | 68 | val get_simproc: Context.generic -> xstring -> simproc | 
| 22236 | 69 |   val def_simproc: {name: string, lhss: string list,
 | 
| 70 | proc: morphism -> simpset -> cterm -> thm option, identifier: thm list} -> | |
| 22201 | 71 | local_theory -> local_theory | 
| 22236 | 72 |   val def_simproc_i: {name: string, lhss: term list,
 | 
| 73 | proc: morphism -> simpset -> cterm -> thm option, identifier: thm list} -> | |
| 22201 | 74 | local_theory -> local_theory | 
| 18033 | 75 | val cong_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list | 
| 76 | val simp_modifiers': (Args.T list -> (Method.modifier * Args.T list)) list | |
| 16014 | 77 | val simp_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list | 
| 78 | val method_setup: (Args.T list -> (Method.modifier * Args.T list)) list | |
| 18708 | 79 | -> theory -> theory | 
| 80 | val easy_setup: thm -> thm list -> theory -> theory | |
| 16014 | 81 | end; | 
| 82 | ||
| 83 | structure Simplifier: SIMPLIFIER = | |
| 84 | struct | |
| 85 | ||
| 21708 | 86 | open MetaSimplifier; | 
| 87 | ||
| 88 | ||
| 17883 
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
 wenzelm parents: 
17723diff
changeset | 89 | (** simpset data **) | 
| 16014 | 90 | |
| 26497 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 91 | structure SimpsetData = GenericDataFun | 
| 22846 | 92 | ( | 
| 26497 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 93 | type T = simpset; | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 94 | val empty = empty_ss; | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 95 | fun extend ss = MetaSimplifier.inherit_context empty_ss ss; | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 96 | fun merge _ = merge_ss; | 
| 22846 | 97 | ); | 
| 16014 | 98 | |
| 26497 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 99 | val get_ss = SimpsetData.get; | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 100 | val map_ss = SimpsetData.map; | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 101 | |
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 102 | |
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 103 | (* attributes *) | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 104 | |
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 105 | fun attrib f = Thm.declaration_attribute (fn th => map_ss (fn ss => f (ss, [th]))); | 
| 16014 | 106 | |
| 26497 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 107 | val simp_add = attrib (op addsimps); | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 108 | val simp_del = attrib (op delsimps); | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 109 | val cong_add = attrib (op addcongs); | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 110 | val cong_del = attrib (op delcongs); | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 111 | |
| 16014 | 112 | |
| 26497 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 113 | (* global simpset *) | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 114 | |
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 115 | fun map_simpset f = Context.theory_map (map_ss f); | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 116 | fun change_simpset f = Context.>> (Context.map_theory (map_simpset f)); | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 117 | fun simpset_of thy = MetaSimplifier.context (ProofContext.init thy) (get_ss (Context.Theory thy)); | 
| 26425 
6561665c5cb1
renamed ML_Context.the_context to ML_Context.the_global_context;
 wenzelm parents: 
24509diff
changeset | 118 | val simpset = simpset_of o ML_Context.the_global_context; | 
| 16014 | 119 | |
| 17883 
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
 wenzelm parents: 
17723diff
changeset | 120 | fun SIMPSET tacf st = tacf (simpset_of (Thm.theory_of_thm st)) st; | 
| 
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
 wenzelm parents: 
17723diff
changeset | 121 | fun SIMPSET' tacf i st = tacf (simpset_of (Thm.theory_of_thm st)) i st; | 
| 16014 | 122 | |
| 17883 
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
 wenzelm parents: 
17723diff
changeset | 123 | fun Addsimps args = change_simpset (fn ss => ss addsimps args); | 
| 
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
 wenzelm parents: 
17723diff
changeset | 124 | fun Delsimps args = change_simpset (fn ss => ss delsimps args); | 
| 
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
 wenzelm parents: 
17723diff
changeset | 125 | fun Addsimprocs args = change_simpset (fn ss => ss addsimprocs args); | 
| 
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
 wenzelm parents: 
17723diff
changeset | 126 | fun Delsimprocs args = change_simpset (fn ss => ss delsimprocs args); | 
| 
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
 wenzelm parents: 
17723diff
changeset | 127 | fun Addcongs args = change_simpset (fn ss => ss addcongs args); | 
| 
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
 wenzelm parents: 
17723diff
changeset | 128 | fun Delcongs args = change_simpset (fn ss => ss delcongs args); | 
| 16014 | 129 | |
| 130 | ||
| 26497 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 131 | (* local simpset *) | 
| 16014 | 132 | |
| 26497 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 133 | fun local_simpset_of ctxt = MetaSimplifier.context ctxt (get_ss (Context.Proof ctxt)); | 
| 16014 | 134 | |
| 27338 | 135 | val _ = ML_Antiquote.value "simpset" | 
| 136 | (Scan.succeed "Simplifier.local_simpset_of (ML_Context.the_local_context ())"); | |
| 22132 | 137 | |
| 16014 | 138 | |
| 17967 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 139 | |
| 22201 | 140 | (** named simprocs **) | 
| 141 | ||
| 23655 
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
 wenzelm parents: 
23598diff
changeset | 142 | fun err_dup_simproc name = error ("Duplicate simproc: " ^ quote name);
 | 
| 22201 | 143 | |
| 22236 | 144 | |
| 22204 | 145 | (* data *) | 
| 146 | ||
| 22201 | 147 | structure Simprocs = GenericDataFun | 
| 148 | ( | |
| 22236 | 149 | type T = simproc NameSpace.table; | 
| 22201 | 150 | val empty = NameSpace.empty_table; | 
| 151 | val extend = I; | |
| 22236 | 152 | fun merge _ simprocs = NameSpace.merge_tables eq_simproc simprocs | 
| 23655 
d2d1138e0ddc
replaced exception TableFun/GraphFun.DUPS by TableFun/GraphFun.DUP;
 wenzelm parents: 
23598diff
changeset | 153 | handle Symtab.DUP dup => err_dup_simproc dup; | 
| 22201 | 154 | ); | 
| 155 | ||
| 22204 | 156 | |
| 157 | (* get simprocs *) | |
| 158 | ||
| 24024 | 159 | fun get_simproc context xname = | 
| 22204 | 160 | let | 
| 24024 | 161 | val (space, tab) = Simprocs.get context; | 
| 22204 | 162 | val name = NameSpace.intern space xname; | 
| 163 | in | |
| 164 | (case Symtab.lookup tab name of | |
| 22236 | 165 | SOME proc => proc | 
| 22204 | 166 |     | NONE => error ("Undefined simplification procedure: " ^ quote name))
 | 
| 167 | end; | |
| 168 | ||
| 27338 | 169 | val _ = ML_Antiquote.value "simproc" (Scan.lift Args.name >> (fn name => | 
| 170 | "Simplifier.get_simproc (ML_Context.the_generic_context ()) " ^ ML_Syntax.print_string name)); | |
| 22204 | 171 | |
| 172 | ||
| 173 | (* define simprocs *) | |
| 22201 | 174 | |
| 175 | local | |
| 176 | ||
| 22236 | 177 | fun gen_simproc prep {name, lhss, proc, identifier} lthy =
 | 
| 22201 | 178 | let | 
| 28991 | 179 | val b = Binding.name name; | 
| 22236 | 180 | val naming = LocalTheory.full_naming lthy; | 
| 181 | val simproc = make_simproc | |
| 28991 | 182 |       {name = LocalTheory.full_name lthy b,
 | 
| 22236 | 183 | lhss = | 
| 184 | let | |
| 185 | val lhss' = prep lthy lhss; | |
| 186 | val ctxt' = lthy | |
| 187 | |> fold Variable.declare_term lhss' | |
| 188 | |> fold Variable.auto_fixes lhss'; | |
| 189 | in Variable.export_terms ctxt' lthy lhss' end | |
| 190 | |> map (Thm.cterm_of (ProofContext.theory_of lthy)), | |
| 191 | proc = proc, | |
| 192 | identifier = identifier} | |
| 193 | |> morph_simproc (LocalTheory.target_morphism lthy); | |
| 22201 | 194 | in | 
| 24024 | 195 | lthy |> LocalTheory.declaration (fn phi => | 
| 22201 | 196 | let | 
| 28991 | 197 | val b' = Morphism.binding phi b; | 
| 22236 | 198 | val simproc' = morph_simproc phi simproc; | 
| 22201 | 199 | in | 
| 24024 | 200 | Simprocs.map (fn simprocs => | 
| 28965 | 201 | NameSpace.bind naming (b', simproc') simprocs |> snd | 
| 28863 | 202 | handle Symtab.DUP dup => err_dup_simproc dup) | 
| 24024 | 203 | #> map_ss (fn ss => ss addsimprocs [simproc']) | 
| 22201 | 204 | end) | 
| 205 | end; | |
| 206 | ||
| 207 | in | |
| 208 | ||
| 24509 
23ee6b7788c2
replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
 wenzelm parents: 
24124diff
changeset | 209 | val def_simproc = gen_simproc Syntax.read_terms; | 
| 
23ee6b7788c2
replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
 wenzelm parents: 
24124diff
changeset | 210 | val def_simproc_i = gen_simproc Syntax.check_terms; | 
| 22201 | 211 | |
| 212 | end; | |
| 213 | ||
| 214 | ||
| 215 | ||
| 17967 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 216 | (** simplification tactics and rules **) | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 217 | |
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 218 | fun solve_all_tac solvers ss = | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 219 | let | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 220 |     val (_, {subgoal_tac, ...}) = MetaSimplifier.rep_ss ss;
 | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 221 | val solve_tac = subgoal_tac (MetaSimplifier.set_solvers solvers ss) THEN_ALL_NEW (K no_tac); | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 222 | in DEPTH_SOLVE (solve_tac 1) end; | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 223 | |
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 224 | (*NOTE: may instantiate unknowns that appear also in other subgoals*) | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 225 | fun generic_simp_tac safe mode ss = | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 226 | let | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 227 |     val (_, {loop_tacs, solvers = (unsafe_solvers, solvers), ...}) = MetaSimplifier.rep_ss ss;
 | 
| 21286 
b5e7b80caa6a
introduces canonical AList functions for loop_tacs
 haftmann parents: 
20872diff
changeset | 228 | val loop_tac = FIRST' (map (fn (_, tac) => tac ss) (rev loop_tacs)); | 
| 17967 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 229 | val solve_tac = FIRST' (map (MetaSimplifier.solver ss) | 
| 22717 | 230 | (rev (if safe then solvers else unsafe_solvers))); | 
| 17967 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 231 | |
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 232 | fun simp_loop_tac i = | 
| 23536 
60a1672e298e
moved (asm_)rewrite_goal_tac from goal.ML to meta_simplifier.ML (no longer depends on SELECT_GOAL);
 wenzelm parents: 
23086diff
changeset | 233 | asm_rewrite_goal_tac mode (solve_all_tac unsafe_solvers) ss i THEN | 
| 17967 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 234 | (solve_tac i ORELSE TRY ((loop_tac THEN_ALL_NEW simp_loop_tac) i)); | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 235 | in simp_loop_tac end; | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 236 | |
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 237 | local | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 238 | |
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 239 | fun simp rew mode ss thm = | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 240 | let | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 241 |     val (_, {solvers = (unsafe_solvers, _), ...}) = MetaSimplifier.rep_ss ss;
 | 
| 22717 | 242 | val tacf = solve_all_tac (rev unsafe_solvers); | 
| 17967 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 243 | fun prover s th = Option.map #1 (Seq.pull (tacf s th)); | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 244 | in rew mode prover ss thm end; | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 245 | |
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 246 | in | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 247 | |
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 248 | val simp_thm = simp MetaSimplifier.rewrite_thm; | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 249 | val simp_cterm = simp MetaSimplifier.rewrite_cterm; | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 250 | |
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 251 | end; | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 252 | |
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 253 | |
| 16806 | 254 | (* tactics *) | 
| 255 | ||
| 16014 | 256 | val simp_tac = generic_simp_tac false (false, false, false); | 
| 257 | val asm_simp_tac = generic_simp_tac false (false, true, false); | |
| 258 | val full_simp_tac = generic_simp_tac false (true, false, false); | |
| 259 | val asm_lr_simp_tac = generic_simp_tac false (true, true, false); | |
| 260 | val asm_full_simp_tac = generic_simp_tac false (true, true, true); | |
| 261 | val safe_asm_full_simp_tac = generic_simp_tac true (true, true, true); | |
| 262 | ||
| 263 | (*the abstraction over the proof state delays the dereferencing*) | |
| 264 | fun Simp_tac i st = simp_tac (simpset ()) i st; | |
| 265 | fun Asm_simp_tac i st = asm_simp_tac (simpset ()) i st; | |
| 266 | fun Full_simp_tac i st = full_simp_tac (simpset ()) i st; | |
| 267 | fun Asm_lr_simp_tac i st = asm_lr_simp_tac (simpset ()) i st; | |
| 268 | fun Asm_full_simp_tac i st = asm_full_simp_tac (simpset ()) i st; | |
| 269 | ||
| 16806 | 270 | |
| 271 | (* conversions *) | |
| 272 | ||
| 17967 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 273 | val simplify = simp_thm (false, false, false); | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 274 | val asm_simplify = simp_thm (false, true, false); | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 275 | val full_simplify = simp_thm (true, false, false); | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 276 | val asm_lr_simplify = simp_thm (true, true, false); | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 277 | val asm_full_simplify = simp_thm (true, true, true); | 
| 16014 | 278 | |
| 17967 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 279 | val rewrite = simp_cterm (false, false, false); | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 280 | val asm_rewrite = simp_cterm (false, true, false); | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 281 | val full_rewrite = simp_cterm (true, false, false); | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 282 | val asm_lr_rewrite = simp_cterm (true, true, false); | 
| 
7a733b7438e1
added simplification tactics and rules (from meta_simplifier.ML);
 wenzelm parents: 
17898diff
changeset | 283 | val asm_full_rewrite = simp_cterm (true, true, true); | 
| 16014 | 284 | |
| 285 | ||
| 286 | ||
| 287 | (** concrete syntax of attributes **) | |
| 288 | ||
| 289 | (* add / del *) | |
| 290 | ||
| 291 | val simpN = "simp"; | |
| 292 | val congN = "cong"; | |
| 293 | val addN = "add"; | |
| 294 | val delN = "del"; | |
| 295 | val onlyN = "only"; | |
| 296 | val no_asmN = "no_asm"; | |
| 297 | val no_asm_useN = "no_asm_use"; | |
| 298 | val no_asm_simpN = "no_asm_simp"; | |
| 299 | val asm_lrN = "asm_lr"; | |
| 300 | ||
| 301 | ||
| 24024 | 302 | (* simprocs *) | 
| 303 | ||
| 304 | local | |
| 305 | ||
| 306 | val add_del = | |
| 307 | (Args.del -- Args.colon >> K (op delsimprocs) || | |
| 308 | Scan.option (Args.add -- Args.colon) >> K (op addsimprocs)) | |
| 309 | >> (fn f => fn simproc => fn phi => Thm.declaration_attribute | |
| 310 | (K (map_ss (fn ss => f (ss, [morph_simproc phi simproc]))))); | |
| 311 | ||
| 312 | in | |
| 313 | ||
| 314 | val simproc_att = Attrib.syntax | |
| 315 | (Scan.peek (fn context => | |
| 316 | add_del :|-- (fn decl => | |
| 317 | Scan.repeat1 (Args.named_attribute (decl o get_simproc context)) | |
| 318 | >> (Library.apply o map Morphism.form)))); | |
| 319 | ||
| 320 | end; | |
| 24124 
4399175e3014
turned simp_depth_limit into configuration option;
 wenzelm parents: 
24024diff
changeset | 321 | |
| 24024 | 322 | |
| 16014 | 323 | (* conversions *) | 
| 324 | ||
| 325 | local | |
| 326 | ||
| 327 | fun conv_mode x = | |
| 328 | ((Args.parens (Args.$$$ no_asmN) >> K simplify || | |
| 329 | Args.parens (Args.$$$ no_asm_simpN) >> K asm_simplify || | |
| 330 | Args.parens (Args.$$$ no_asm_useN) >> K full_simplify || | |
| 331 | Scan.succeed asm_full_simplify) |> Scan.lift) x; | |
| 332 | ||
| 333 | in | |
| 334 | ||
| 18688 | 335 | val simplified = | 
| 27021 | 336 | Attrib.syntax (conv_mode -- Attrib.thms >> (fn (f, ths) => Thm.rule_attribute (fn context => | 
| 337 | f ((if null ths then I else MetaSimplifier.clear_ss) | |
| 338 | (local_simpset_of (Context.proof_of context)) addsimps ths)))); | |
| 16014 | 339 | |
| 340 | end; | |
| 341 | ||
| 342 | ||
| 343 | (* setup attributes *) | |
| 344 | ||
| 26463 | 345 | val _ = Context.>> (Context.map_theory | 
| 18708 | 346 | (Attrib.add_attributes | 
| 24024 | 347 | [(simpN, Attrib.add_del_args simp_add simp_del, "declaration of Simplifier rewrite rule"), | 
| 18728 | 348 | (congN, Attrib.add_del_args cong_add cong_del, "declaration of Simplifier congruence rule"), | 
| 24024 | 349 |     ("simproc", simproc_att, "declaration of simplification procedures"),
 | 
| 26463 | 350 |     ("simplified", simplified, "simplified rule")]));
 | 
| 16014 | 351 | |
| 352 | ||
| 353 | ||
| 354 | (** proof methods **) | |
| 355 | ||
| 356 | (* simplification *) | |
| 357 | ||
| 358 | val simp_options = | |
| 359 | (Args.parens (Args.$$$ no_asmN) >> K simp_tac || | |
| 360 | Args.parens (Args.$$$ no_asm_simpN) >> K asm_simp_tac || | |
| 361 | Args.parens (Args.$$$ no_asm_useN) >> K full_simp_tac || | |
| 362 | Args.parens (Args.$$$ asm_lrN) >> K asm_lr_simp_tac || | |
| 363 | Scan.succeed asm_full_simp_tac); | |
| 364 | ||
| 365 | val cong_modifiers = | |
| 18728 | 366 | [Args.$$$ congN -- Args.colon >> K ((I, cong_add): Method.modifier), | 
| 367 | Args.$$$ congN -- Args.add -- Args.colon >> K (I, cong_add), | |
| 368 | Args.$$$ congN -- Args.del -- Args.colon >> K (I, cong_del)]; | |
| 16014 | 369 | |
| 370 | val simp_modifiers = | |
| 18728 | 371 | [Args.$$$ simpN -- Args.colon >> K (I, simp_add), | 
| 372 | Args.$$$ simpN -- Args.add -- Args.colon >> K (I, simp_add), | |
| 373 | Args.$$$ simpN -- Args.del -- Args.colon >> K (I, simp_del), | |
| 17883 
efa1bc2bdcc6
removed obsolete/experimental context components (superceded by Simplifier.the_context);
 wenzelm parents: 
17723diff
changeset | 374 | Args.$$$ simpN -- Args.$$$ onlyN -- Args.colon | 
| 26497 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 375 | >> K (Context.proof_map (map_ss MetaSimplifier.clear_ss), simp_add)] | 
| 16014 | 376 | @ cong_modifiers; | 
| 377 | ||
| 378 | val simp_modifiers' = | |
| 18728 | 379 | [Args.add -- Args.colon >> K (I, simp_add), | 
| 380 | Args.del -- Args.colon >> K (I, simp_del), | |
| 18688 | 381 | Args.$$$ onlyN -- Args.colon | 
| 26497 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 382 | >> K (Context.proof_map (map_ss MetaSimplifier.clear_ss), simp_add)] | 
| 16014 | 383 | @ cong_modifiers; | 
| 384 | ||
| 385 | fun simp_args more_mods = | |
| 24124 
4399175e3014
turned simp_depth_limit into configuration option;
 wenzelm parents: 
24024diff
changeset | 386 | Method.sectioned_args (Args.bang_facts -- Scan.lift simp_options) | 
| 16684 
7b58002668c0
methods: added simp_flags argument, added "depth_limit" flag;
 wenzelm parents: 
16458diff
changeset | 387 | (more_mods @ simp_modifiers'); | 
| 16014 | 388 | |
| 24124 
4399175e3014
turned simp_depth_limit into configuration option;
 wenzelm parents: 
24024diff
changeset | 389 | fun simp_method (prems, tac) ctxt = Method.METHOD (fn facts => | 
| 16014 | 390 | ALLGOALS (Method.insert_tac (prems @ facts)) THEN | 
| 24124 
4399175e3014
turned simp_depth_limit into configuration option;
 wenzelm parents: 
24024diff
changeset | 391 | (CHANGED_PROP o ALLGOALS o tac) (local_simpset_of ctxt)); | 
| 16014 | 392 | |
| 24124 
4399175e3014
turned simp_depth_limit into configuration option;
 wenzelm parents: 
24024diff
changeset | 393 | fun simp_method' (prems, tac) ctxt = Method.METHOD (fn facts => | 
| 16014 | 394 | HEADGOAL (Method.insert_tac (prems @ facts) THEN' | 
| 24124 
4399175e3014
turned simp_depth_limit into configuration option;
 wenzelm parents: 
24024diff
changeset | 395 | ((CHANGED_PROP) oo tac) (local_simpset_of ctxt))); | 
| 16014 | 396 | |
| 397 | ||
| 398 | ||
| 18708 | 399 | (** setup **) | 
| 400 | ||
| 401 | fun method_setup more_mods = Method.add_methods | |
| 16014 | 402 | [(simpN, simp_args more_mods simp_method', "simplification"), | 
| 403 |   ("simp_all", simp_args more_mods simp_method, "simplification (all goals)")];
 | |
| 404 | ||
| 26497 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 405 | fun easy_setup reflect trivs = method_setup [] #> Context.theory_map (map_ss (fn _ => | 
| 16014 | 406 | let | 
| 407 | val trivialities = Drule.reflexive_thm :: trivs; | |
| 408 | ||
| 409 | fun unsafe_solver_tac prems = FIRST' [resolve_tac (trivialities @ prems), assume_tac]; | |
| 410 | val unsafe_solver = mk_solver "easy unsafe" unsafe_solver_tac; | |
| 411 | ||
| 412 | (*no premature instantiation of variables during simplification*) | |
| 413 | fun safe_solver_tac prems = FIRST' [match_tac (trivialities @ prems), eq_assume_tac]; | |
| 414 | val safe_solver = mk_solver "easy safe" safe_solver_tac; | |
| 415 | ||
| 416 | fun mk_eq thm = | |
| 20872 | 417 | if can Logic.dest_equals (Thm.concl_of thm) then [thm] | 
| 16014 | 418 | else [thm RS reflect] handle THM _ => []; | 
| 419 | ||
| 26653 | 420 | fun mksimps thm = mk_eq (Thm.forall_elim_vars (#maxidx (Thm.rep_thm thm) + 1) thm); | 
| 26497 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 421 | in | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 422 | empty_ss setsubgoaler asm_simp_tac | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 423 | setSSolver safe_solver | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 424 | setSolver unsafe_solver | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 425 | setmksimps mksimps | 
| 
1873915c64a9
purely functional setup of claset/simpset/clasimpset;
 wenzelm parents: 
26463diff
changeset | 426 | end)); | 
| 16014 | 427 | |
| 428 | end; | |
| 429 | ||
| 430 | structure BasicSimplifier: BASIC_SIMPLIFIER = Simplifier; | |
| 431 | open BasicSimplifier; |