src/Pure/simplifier.ML
author wenzelm
Mon Aug 08 17:23:15 2011 +0200 (2011-08-08)
changeset 44058 ae85c5d64913
parent 43597 b4a093e755db
child 45290 f599ac41e7f5
permissions -rw-r--r--
misc tuning -- eliminated old-fashioned rep_thm;
wenzelm@16014
     1
(*  Title:      Pure/simplifier.ML
wenzelm@16014
     2
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
wenzelm@16014
     3
wenzelm@16014
     4
Generic simplifier, suitable for most logics (see also
haftmann@41386
     5
raw_simplifier.ML for the actual meta-level rewriting engine).
wenzelm@16014
     6
*)
wenzelm@16014
     7
wenzelm@16014
     8
signature BASIC_SIMPLIFIER =
wenzelm@16014
     9
sig
wenzelm@41228
    10
  include BASIC_RAW_SIMPLIFIER
wenzelm@42795
    11
  val map_simpset: (simpset -> simpset) -> Proof.context -> Proof.context
wenzelm@42795
    12
  val simpset_of: Proof.context -> simpset
wenzelm@32148
    13
  val global_simpset_of: theory -> simpset
wenzelm@16014
    14
  val Addsimprocs: simproc list -> unit
wenzelm@16014
    15
  val Delsimprocs: simproc list -> unit
wenzelm@17967
    16
  val generic_simp_tac: bool -> bool * bool * bool -> simpset -> int -> tactic
wenzelm@16014
    17
  val safe_asm_full_simp_tac: simpset -> int -> tactic
wenzelm@35613
    18
  val simp_tac: simpset -> int -> tactic
wenzelm@35613
    19
  val asm_simp_tac: simpset -> int -> tactic
wenzelm@35613
    20
  val full_simp_tac: simpset -> int -> tactic
wenzelm@35613
    21
  val asm_lr_simp_tac: simpset -> int -> tactic
wenzelm@35613
    22
  val asm_full_simp_tac: simpset -> int -> tactic
wenzelm@35613
    23
  val simplify: simpset -> thm -> thm
wenzelm@35613
    24
  val asm_simplify: simpset -> thm -> thm
wenzelm@35613
    25
  val full_simplify: simpset -> thm -> thm
wenzelm@35613
    26
  val asm_lr_simplify: simpset -> thm -> thm
wenzelm@16014
    27
  val asm_full_simplify: simpset -> thm -> thm
wenzelm@16014
    28
end;
wenzelm@16014
    29
wenzelm@16014
    30
signature SIMPLIFIER =
wenzelm@16014
    31
sig
wenzelm@16014
    32
  include BASIC_SIMPLIFIER
wenzelm@42795
    33
  val map_simpset_global: (simpset -> simpset) -> theory -> theory
wenzelm@30356
    34
  val pretty_ss: Proof.context -> simpset -> Pretty.T
wenzelm@17004
    35
  val clear_ss: simpset -> simpset
wenzelm@32738
    36
  val debug_bounds: bool Unsynchronized.ref
wenzelm@43597
    37
  val prems_of: simpset -> thm list
wenzelm@41226
    38
  val add_simp: thm -> simpset -> simpset
wenzelm@41226
    39
  val del_simp: thm -> simpset -> simpset
wenzelm@41226
    40
  val add_prems: thm list -> simpset -> simpset
wenzelm@17883
    41
  val inherit_context: simpset -> simpset -> simpset
wenzelm@17898
    42
  val the_context: simpset -> Proof.context
wenzelm@17898
    43
  val context: Proof.context -> simpset -> simpset
haftmann@37441
    44
  val global_context: theory -> simpset -> simpset
wenzelm@36600
    45
  val with_context: Proof.context -> (simpset -> simpset) -> simpset -> simpset
wenzelm@42795
    46
  val simproc_global_i: theory -> string -> term list ->
wenzelm@42795
    47
    (theory -> simpset -> term -> thm option) -> simproc
wenzelm@42795
    48
  val simproc_global: theory -> string -> string list ->
wenzelm@42795
    49
    (theory -> simpset -> term -> thm option) -> simproc
wenzelm@35613
    50
  val rewrite: simpset -> conv
wenzelm@35613
    51
  val asm_rewrite: simpset -> conv
wenzelm@35613
    52
  val full_rewrite: simpset -> conv
wenzelm@35613
    53
  val asm_lr_rewrite: simpset -> conv
wenzelm@23598
    54
  val asm_full_rewrite: simpset -> conv
wenzelm@22379
    55
  val get_ss: Context.generic -> simpset
wenzelm@22379
    56
  val map_ss: (simpset -> simpset) -> Context.generic -> Context.generic
wenzelm@18728
    57
  val attrib: (simpset * thm list -> simpset) -> attribute
wenzelm@18728
    58
  val simp_add: attribute
wenzelm@18728
    59
  val simp_del: attribute
wenzelm@18728
    60
  val cong_add: attribute
wenzelm@18728
    61
  val cong_del: attribute
wenzelm@42465
    62
  val check_simproc: Proof.context -> xstring * Position.T -> string
wenzelm@42465
    63
  val the_simproc: Proof.context -> string -> simproc
wenzelm@42464
    64
  val def_simproc: {name: binding, lhss: term list,
wenzelm@22236
    65
    proc: morphism -> simpset -> cterm -> thm option, identifier: thm list} ->
wenzelm@22201
    66
    local_theory -> local_theory
wenzelm@42464
    67
  val def_simproc_cmd: {name: binding, lhss: string list,
wenzelm@22236
    68
    proc: morphism -> simpset -> cterm -> thm option, identifier: thm list} ->
wenzelm@22201
    69
    local_theory -> local_theory
wenzelm@30513
    70
  val cong_modifiers: Method.modifier parser list
wenzelm@30513
    71
  val simp_modifiers': Method.modifier parser list
wenzelm@30513
    72
  val simp_modifiers: Method.modifier parser list
wenzelm@30513
    73
  val method_setup: Method.modifier parser list -> theory -> theory
wenzelm@18708
    74
  val easy_setup: thm -> thm list -> theory -> theory
wenzelm@16014
    75
end;
wenzelm@16014
    76
wenzelm@16014
    77
structure Simplifier: SIMPLIFIER =
wenzelm@16014
    78
struct
wenzelm@16014
    79
wenzelm@41228
    80
open Raw_Simplifier;
wenzelm@21708
    81
wenzelm@21708
    82
wenzelm@42465
    83
(** data **)
wenzelm@42465
    84
wenzelm@42465
    85
structure Data = Generic_Data
wenzelm@42465
    86
(
wenzelm@42465
    87
  type T = simpset * simproc Name_Space.table;
wenzelm@42465
    88
  val empty : T = (empty_ss, Name_Space.empty_table "simproc");
wenzelm@42465
    89
  fun extend (ss, tab) = (Raw_Simplifier.inherit_context empty_ss ss, tab);
wenzelm@42465
    90
  fun merge ((ss1, tab1), (ss2, tab2)) =
wenzelm@42465
    91
    (merge_ss (ss1, ss2), Name_Space.merge_tables (tab1, tab2));
wenzelm@42465
    92
);
wenzelm@42465
    93
wenzelm@42465
    94
val get_ss = fst o Data.get;
wenzelm@42465
    95
wenzelm@42465
    96
fun map_ss f context =
wenzelm@42465
    97
  Data.map (apfst ((Raw_Simplifier.with_context (Context.proof_of context) f))) context;
wenzelm@42465
    98
wenzelm@42465
    99
val get_simprocs = snd o Data.get o Context.Proof;
wenzelm@42465
   100
wenzelm@42465
   101
wenzelm@42465
   102
wenzelm@30356
   103
(** pretty printing **)
wenzelm@30356
   104
wenzelm@30356
   105
fun pretty_ss ctxt ss =
wenzelm@30356
   106
  let
wenzelm@30356
   107
    val pretty_cterm = Syntax.pretty_term ctxt o Thm.term_of;
wenzelm@32091
   108
    val pretty_thm = Display.pretty_thm ctxt;
wenzelm@30356
   109
    fun pretty_proc (name, lhss) = Pretty.big_list (name ^ ":") (map pretty_cterm lhss);
wenzelm@30356
   110
    fun pretty_cong (name, thm) =
wenzelm@30356
   111
      Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 1, pretty_thm thm];
wenzelm@30356
   112
wenzelm@30356
   113
    val {simps, procs, congs, loopers, unsafe_solvers, safe_solvers, ...} = dest_ss ss;
wenzelm@30356
   114
  in
wenzelm@30356
   115
    [Pretty.big_list "simplification rules:" (map (pretty_thm o #2) simps),
wenzelm@30356
   116
      Pretty.big_list "simplification procedures:" (map pretty_proc (sort_wrt #1 procs)),
wenzelm@30356
   117
      Pretty.big_list "congruences:" (map pretty_cong congs),
wenzelm@30356
   118
      Pretty.strs ("loopers:" :: map quote loopers),
wenzelm@30356
   119
      Pretty.strs ("unsafe solvers:" :: map quote unsafe_solvers),
wenzelm@30356
   120
      Pretty.strs ("safe solvers:" :: map quote safe_solvers)]
wenzelm@30356
   121
    |> Pretty.chunks
wenzelm@30356
   122
  end;
wenzelm@30356
   123
wenzelm@30356
   124
wenzelm@30356
   125
wenzelm@17883
   126
(** simpset data **)
wenzelm@16014
   127
wenzelm@26497
   128
(* attributes *)
wenzelm@26497
   129
wenzelm@26497
   130
fun attrib f = Thm.declaration_attribute (fn th => map_ss (fn ss => f (ss, [th])));
wenzelm@16014
   131
wenzelm@26497
   132
val simp_add = attrib (op addsimps);
wenzelm@26497
   133
val simp_del = attrib (op delsimps);
wenzelm@26497
   134
val cong_add = attrib (op addcongs);
wenzelm@26497
   135
val cong_del = attrib (op delcongs);
wenzelm@26497
   136
wenzelm@16014
   137
wenzelm@26497
   138
(* local simpset *)
wenzelm@16014
   139
wenzelm@42795
   140
fun map_simpset f = Context.proof_map (map_ss f);
wenzelm@41228
   141
fun simpset_of ctxt = Raw_Simplifier.context ctxt (get_ss (Context.Proof ctxt));
wenzelm@16014
   142
wenzelm@43560
   143
val _ = Context.>> (Context.map_theory
wenzelm@43560
   144
  (ML_Antiquote.value (Binding.name "simpset")
wenzelm@43560
   145
    (Scan.succeed "Simplifier.simpset_of (ML_Context.the_local_context ())")));
wenzelm@22132
   146
wenzelm@16014
   147
wenzelm@42795
   148
(* global simpset *)
wenzelm@42795
   149
wenzelm@42795
   150
fun map_simpset_global f = Context.theory_map (map_ss f);
wenzelm@42795
   151
fun global_simpset_of thy =
wenzelm@42795
   152
  Raw_Simplifier.context (Proof_Context.init_global thy) (get_ss (Context.Theory thy));
wenzelm@42795
   153
wenzelm@42795
   154
fun Addsimprocs args = Context.>> (map_ss (fn ss => ss addsimprocs args));
wenzelm@42795
   155
fun Delsimprocs args = Context.>> (map_ss (fn ss => ss delsimprocs args));
wenzelm@42795
   156
wenzelm@42795
   157
wenzelm@17967
   158
wenzelm@22201
   159
(** named simprocs **)
wenzelm@22201
   160
wenzelm@22204
   161
(* get simprocs *)
wenzelm@22204
   162
wenzelm@43560
   163
fun check_simproc ctxt = Name_Space.check ctxt (get_simprocs ctxt) #> #1;
wenzelm@42466
   164
val the_simproc = Name_Space.get o get_simprocs;
wenzelm@42465
   165
wenzelm@42464
   166
val _ =
wenzelm@43560
   167
  Context.>> (Context.map_theory
wenzelm@43560
   168
   (ML_Antiquote.value (Binding.name "simproc")
wenzelm@43560
   169
      (Args.context -- Scan.lift (Parse.position Args.name)
wenzelm@43560
   170
        >> (fn (ctxt, name) =>
wenzelm@43560
   171
          "Simplifier.the_simproc (ML_Context.the_local_context ()) " ^
wenzelm@43560
   172
            ML_Syntax.print_string (check_simproc ctxt name)))));
wenzelm@22204
   173
wenzelm@22204
   174
wenzelm@22204
   175
(* define simprocs *)
wenzelm@22201
   176
wenzelm@22201
   177
local
wenzelm@22201
   178
wenzelm@42464
   179
fun gen_simproc prep {name = b, lhss, proc, identifier} lthy =
wenzelm@22201
   180
  let
wenzelm@33671
   181
    val naming = Local_Theory.naming_of lthy;
wenzelm@22236
   182
    val simproc = make_simproc
wenzelm@33169
   183
      {name = Name_Space.full_name naming b,
wenzelm@22236
   184
       lhss =
wenzelm@22236
   185
        let
wenzelm@22236
   186
          val lhss' = prep lthy lhss;
wenzelm@22236
   187
          val ctxt' = lthy
wenzelm@22236
   188
            |> fold Variable.declare_term lhss'
wenzelm@22236
   189
            |> fold Variable.auto_fixes lhss';
wenzelm@22236
   190
        in Variable.export_terms ctxt' lthy lhss' end
wenzelm@42360
   191
        |> map (Thm.cterm_of (Proof_Context.theory_of lthy)),
wenzelm@22236
   192
       proc = proc,
wenzelm@33551
   193
       identifier = identifier};
wenzelm@22201
   194
  in
wenzelm@42375
   195
    lthy |> Local_Theory.declaration false (fn phi => fn context =>
wenzelm@22201
   196
      let
haftmann@28991
   197
        val b' = Morphism.binding phi b;
wenzelm@22236
   198
        val simproc' = morph_simproc phi simproc;
wenzelm@22201
   199
      in
wenzelm@42375
   200
        context
wenzelm@42465
   201
        |> Data.map (fn (ss, tab) =>
wenzelm@42465
   202
          (ss addsimprocs [simproc'],
wenzelm@42465
   203
            #2 (Name_Space.define (Context.proof_of context) true naming (b', simproc') tab)))
wenzelm@22201
   204
      end)
wenzelm@22201
   205
  end;
wenzelm@22201
   206
wenzelm@22201
   207
in
wenzelm@22201
   208
wenzelm@42464
   209
val def_simproc = gen_simproc Syntax.check_terms;
wenzelm@42464
   210
val def_simproc_cmd = gen_simproc Syntax.read_terms;
wenzelm@22201
   211
wenzelm@22201
   212
end;
wenzelm@22201
   213
wenzelm@22201
   214
wenzelm@22201
   215
wenzelm@17967
   216
(** simplification tactics and rules **)
wenzelm@17967
   217
wenzelm@17967
   218
fun solve_all_tac solvers ss =
wenzelm@17967
   219
  let
wenzelm@41228
   220
    val (_, {subgoal_tac, ...}) = Raw_Simplifier.internal_ss ss;
wenzelm@41228
   221
    val solve_tac = subgoal_tac (Raw_Simplifier.set_solvers solvers ss) THEN_ALL_NEW (K no_tac);
wenzelm@17967
   222
  in DEPTH_SOLVE (solve_tac 1) end;
wenzelm@17967
   223
wenzelm@17967
   224
(*NOTE: may instantiate unknowns that appear also in other subgoals*)
wenzelm@17967
   225
fun generic_simp_tac safe mode ss =
wenzelm@17967
   226
  let
wenzelm@41228
   227
    val (_, {loop_tacs, solvers = (unsafe_solvers, solvers), ...}) = Raw_Simplifier.internal_ss ss;
haftmann@21286
   228
    val loop_tac = FIRST' (map (fn (_, tac) => tac ss) (rev loop_tacs));
wenzelm@41228
   229
    val solve_tac = FIRST' (map (Raw_Simplifier.solver ss)
haftmann@22717
   230
      (rev (if safe then solvers else unsafe_solvers)));
wenzelm@17967
   231
wenzelm@17967
   232
    fun simp_loop_tac i =
wenzelm@41253
   233
      Raw_Simplifier.asm_rewrite_goal_tac mode (solve_all_tac unsafe_solvers) ss i THEN
wenzelm@17967
   234
      (solve_tac i ORELSE TRY ((loop_tac THEN_ALL_NEW simp_loop_tac) i));
wenzelm@17967
   235
  in simp_loop_tac end;
wenzelm@17967
   236
wenzelm@17967
   237
local
wenzelm@17967
   238
wenzelm@17967
   239
fun simp rew mode ss thm =
wenzelm@17967
   240
  let
wenzelm@41228
   241
    val (_, {solvers = (unsafe_solvers, _), ...}) = Raw_Simplifier.internal_ss ss;
haftmann@22717
   242
    val tacf = solve_all_tac (rev unsafe_solvers);
wenzelm@17967
   243
    fun prover s th = Option.map #1 (Seq.pull (tacf s th));
wenzelm@17967
   244
  in rew mode prover ss thm end;
wenzelm@17967
   245
wenzelm@17967
   246
in
wenzelm@17967
   247
wenzelm@41228
   248
val simp_thm = simp Raw_Simplifier.rewrite_thm;
wenzelm@41228
   249
val simp_cterm = simp Raw_Simplifier.rewrite_cterm;
wenzelm@17967
   250
wenzelm@17967
   251
end;
wenzelm@17967
   252
wenzelm@17967
   253
wenzelm@16806
   254
(* tactics *)
wenzelm@16806
   255
wenzelm@16014
   256
val simp_tac = generic_simp_tac false (false, false, false);
wenzelm@16014
   257
val asm_simp_tac = generic_simp_tac false (false, true, false);
wenzelm@16014
   258
val full_simp_tac = generic_simp_tac false (true, false, false);
wenzelm@16014
   259
val asm_lr_simp_tac = generic_simp_tac false (true, true, false);
wenzelm@16014
   260
val asm_full_simp_tac = generic_simp_tac false (true, true, true);
wenzelm@16014
   261
val safe_asm_full_simp_tac = generic_simp_tac true (true, true, true);
wenzelm@16014
   262
wenzelm@16806
   263
wenzelm@16806
   264
(* conversions *)
wenzelm@16806
   265
wenzelm@17967
   266
val          simplify = simp_thm (false, false, false);
wenzelm@17967
   267
val      asm_simplify = simp_thm (false, true, false);
wenzelm@17967
   268
val     full_simplify = simp_thm (true, false, false);
wenzelm@17967
   269
val   asm_lr_simplify = simp_thm (true, true, false);
wenzelm@17967
   270
val asm_full_simplify = simp_thm (true, true, true);
wenzelm@16014
   271
wenzelm@17967
   272
val          rewrite = simp_cterm (false, false, false);
wenzelm@17967
   273
val      asm_rewrite = simp_cterm (false, true, false);
wenzelm@17967
   274
val     full_rewrite = simp_cterm (true, false, false);
wenzelm@17967
   275
val   asm_lr_rewrite = simp_cterm (true, true, false);
wenzelm@17967
   276
val asm_full_rewrite = simp_cterm (true, true, true);
wenzelm@16014
   277
wenzelm@16014
   278
wenzelm@16014
   279
wenzelm@16014
   280
(** concrete syntax of attributes **)
wenzelm@16014
   281
wenzelm@16014
   282
(* add / del *)
wenzelm@16014
   283
wenzelm@16014
   284
val simpN = "simp";
wenzelm@16014
   285
val congN = "cong";
wenzelm@16014
   286
val onlyN = "only";
wenzelm@16014
   287
val no_asmN = "no_asm";
wenzelm@16014
   288
val no_asm_useN = "no_asm_use";
wenzelm@16014
   289
val no_asm_simpN = "no_asm_simp";
wenzelm@16014
   290
val asm_lrN = "asm_lr";
wenzelm@16014
   291
wenzelm@16014
   292
wenzelm@24024
   293
(* simprocs *)
wenzelm@24024
   294
wenzelm@24024
   295
local
wenzelm@24024
   296
wenzelm@24024
   297
val add_del =
wenzelm@24024
   298
  (Args.del -- Args.colon >> K (op delsimprocs) ||
wenzelm@24024
   299
    Scan.option (Args.add -- Args.colon) >> K (op addsimprocs))
wenzelm@24024
   300
  >> (fn f => fn simproc => fn phi => Thm.declaration_attribute
wenzelm@24024
   301
      (K (map_ss (fn ss => f (ss, [morph_simproc phi simproc])))));
wenzelm@24024
   302
wenzelm@24024
   303
in
wenzelm@24024
   304
wenzelm@30528
   305
val simproc_att =
wenzelm@42465
   306
  (Args.context -- Scan.lift add_del) :|-- (fn (ctxt, decl) =>
wenzelm@42465
   307
    Scan.repeat1 (Scan.lift (Args.named_attribute (decl o the_simproc ctxt o check_simproc ctxt))))
wenzelm@42465
   308
  >> (Library.apply o map Morphism.form);
wenzelm@24024
   309
wenzelm@24024
   310
end;
wenzelm@24124
   311
wenzelm@24024
   312
wenzelm@16014
   313
(* conversions *)
wenzelm@16014
   314
wenzelm@16014
   315
local
wenzelm@16014
   316
wenzelm@16014
   317
fun conv_mode x =
wenzelm@16014
   318
  ((Args.parens (Args.$$$ no_asmN) >> K simplify ||
wenzelm@16014
   319
    Args.parens (Args.$$$ no_asm_simpN) >> K asm_simplify ||
wenzelm@16014
   320
    Args.parens (Args.$$$ no_asm_useN) >> K full_simplify ||
wenzelm@16014
   321
    Scan.succeed asm_full_simplify) |> Scan.lift) x;
wenzelm@16014
   322
wenzelm@16014
   323
in
wenzelm@16014
   324
wenzelm@30528
   325
val simplified = conv_mode -- Attrib.thms >>
wenzelm@30528
   326
  (fn (f, ths) => Thm.rule_attribute (fn context =>
wenzelm@41228
   327
    f ((if null ths then I else Raw_Simplifier.clear_ss)
wenzelm@32148
   328
        (simpset_of (Context.proof_of context)) addsimps ths)));
wenzelm@16014
   329
wenzelm@16014
   330
end;
wenzelm@16014
   331
wenzelm@16014
   332
wenzelm@16014
   333
(* setup attributes *)
wenzelm@16014
   334
wenzelm@26463
   335
val _ = Context.>> (Context.map_theory
wenzelm@30528
   336
 (Attrib.setup (Binding.name simpN) (Attrib.add_del simp_add simp_del)
wenzelm@30528
   337
    "declaration of Simplifier rewrite rule" #>
wenzelm@30528
   338
  Attrib.setup (Binding.name congN) (Attrib.add_del cong_add cong_del)
wenzelm@30528
   339
    "declaration of Simplifier congruence rule" #>
wenzelm@33671
   340
  Attrib.setup (Binding.name "simproc") simproc_att
wenzelm@33671
   341
    "declaration of simplification procedures" #>
wenzelm@30528
   342
  Attrib.setup (Binding.name "simplified") simplified "simplified rule"));
wenzelm@16014
   343
wenzelm@16014
   344
wenzelm@16014
   345
wenzelm@31300
   346
(** method syntax **)
wenzelm@16014
   347
wenzelm@16014
   348
val cong_modifiers =
wenzelm@18728
   349
 [Args.$$$ congN -- Args.colon >> K ((I, cong_add): Method.modifier),
wenzelm@18728
   350
  Args.$$$ congN -- Args.add -- Args.colon >> K (I, cong_add),
wenzelm@18728
   351
  Args.$$$ congN -- Args.del -- Args.colon >> K (I, cong_del)];
wenzelm@16014
   352
wenzelm@16014
   353
val simp_modifiers =
wenzelm@18728
   354
 [Args.$$$ simpN -- Args.colon >> K (I, simp_add),
wenzelm@18728
   355
  Args.$$$ simpN -- Args.add -- Args.colon >> K (I, simp_add),
wenzelm@18728
   356
  Args.$$$ simpN -- Args.del -- Args.colon >> K (I, simp_del),
wenzelm@17883
   357
  Args.$$$ simpN -- Args.$$$ onlyN -- Args.colon
wenzelm@41228
   358
    >> K (Context.proof_map (map_ss Raw_Simplifier.clear_ss), simp_add)]
wenzelm@16014
   359
   @ cong_modifiers;
wenzelm@16014
   360
wenzelm@16014
   361
val simp_modifiers' =
wenzelm@18728
   362
 [Args.add -- Args.colon >> K (I, simp_add),
wenzelm@18728
   363
  Args.del -- Args.colon >> K (I, simp_del),
wenzelm@18688
   364
  Args.$$$ onlyN -- Args.colon
wenzelm@41228
   365
    >> K (Context.proof_map (map_ss Raw_Simplifier.clear_ss), simp_add)]
wenzelm@16014
   366
   @ cong_modifiers;
wenzelm@16014
   367
wenzelm@31300
   368
val simp_options =
wenzelm@31300
   369
 (Args.parens (Args.$$$ no_asmN) >> K simp_tac ||
wenzelm@31300
   370
  Args.parens (Args.$$$ no_asm_simpN) >> K asm_simp_tac ||
wenzelm@31300
   371
  Args.parens (Args.$$$ no_asm_useN) >> K full_simp_tac ||
wenzelm@31300
   372
  Args.parens (Args.$$$ asm_lrN) >> K asm_lr_simp_tac ||
wenzelm@31300
   373
  Scan.succeed asm_full_simp_tac);
wenzelm@16014
   374
wenzelm@31300
   375
fun simp_method more_mods meth =
wenzelm@35613
   376
  Scan.lift simp_options --|
wenzelm@31300
   377
    Method.sections (more_mods @ simp_modifiers') >>
wenzelm@35613
   378
    (fn tac => fn ctxt => METHOD (fn facts => meth ctxt tac facts));
wenzelm@16014
   379
wenzelm@16014
   380
wenzelm@16014
   381
wenzelm@18708
   382
(** setup **)
wenzelm@18708
   383
wenzelm@31300
   384
fun method_setup more_mods =
wenzelm@31300
   385
  Method.setup (Binding.name simpN)
wenzelm@31300
   386
    (simp_method more_mods (fn ctxt => fn tac => fn facts =>
wenzelm@31300
   387
      HEADGOAL (Method.insert_tac facts THEN'
wenzelm@32148
   388
        (CHANGED_PROP oo tac) (simpset_of ctxt))))
wenzelm@31300
   389
    "simplification" #>
wenzelm@31300
   390
  Method.setup (Binding.name "simp_all")
wenzelm@31300
   391
    (simp_method more_mods (fn ctxt => fn tac => fn facts =>
wenzelm@31300
   392
      ALLGOALS (Method.insert_tac facts) THEN
wenzelm@42372
   393
        (CHANGED_PROP o PARALLEL_GOALS o ALLGOALS o tac) (simpset_of ctxt)))
wenzelm@31300
   394
    "simplification (all goals)";
wenzelm@16014
   395
wenzelm@26497
   396
fun easy_setup reflect trivs = method_setup [] #> Context.theory_map (map_ss (fn _ =>
wenzelm@16014
   397
  let
wenzelm@16014
   398
    val trivialities = Drule.reflexive_thm :: trivs;
wenzelm@16014
   399
wenzelm@43597
   400
    fun unsafe_solver_tac ss =
wenzelm@43597
   401
      FIRST' [resolve_tac (trivialities @ Raw_Simplifier.prems_of ss), assume_tac];
wenzelm@16014
   402
    val unsafe_solver = mk_solver "easy unsafe" unsafe_solver_tac;
wenzelm@16014
   403
wenzelm@16014
   404
    (*no premature instantiation of variables during simplification*)
wenzelm@43597
   405
    fun safe_solver_tac ss =
wenzelm@43597
   406
      FIRST' [match_tac (trivialities @ Raw_Simplifier.prems_of ss), eq_assume_tac];
wenzelm@16014
   407
    val safe_solver = mk_solver "easy safe" safe_solver_tac;
wenzelm@16014
   408
wenzelm@16014
   409
    fun mk_eq thm =
wenzelm@20872
   410
      if can Logic.dest_equals (Thm.concl_of thm) then [thm]
wenzelm@16014
   411
      else [thm RS reflect] handle THM _ => [];
wenzelm@16014
   412
wenzelm@44058
   413
    fun mksimps thm = mk_eq (Thm.forall_elim_vars (Thm.maxidx_of thm + 1) thm);
wenzelm@26497
   414
  in
wenzelm@26497
   415
    empty_ss setsubgoaler asm_simp_tac
wenzelm@26497
   416
    setSSolver safe_solver
wenzelm@26497
   417
    setSolver unsafe_solver
wenzelm@36543
   418
    setmksimps (K mksimps)
wenzelm@26497
   419
  end));
wenzelm@16014
   420
wenzelm@16014
   421
end;
wenzelm@16014
   422
wenzelm@32738
   423
structure Basic_Simplifier: BASIC_SIMPLIFIER = Simplifier;
wenzelm@32738
   424
open Basic_Simplifier;