src/Pure/simplifier.ML
author wenzelm
Sat Nov 04 15:24:40 2017 +0100 (19 months ago)
changeset 67003 49850a679c2c
parent 64556 851ae0e7b09c
child 67146 909dcdec2122
permissions -rw-r--r--
more robust sorted_entries;
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@51717
    11
  val simp_tac: Proof.context -> int -> tactic
wenzelm@51717
    12
  val asm_simp_tac: Proof.context -> int -> tactic
wenzelm@51717
    13
  val full_simp_tac: Proof.context -> int -> tactic
wenzelm@51717
    14
  val asm_lr_simp_tac: Proof.context -> int -> tactic
wenzelm@51717
    15
  val asm_full_simp_tac: Proof.context -> int -> tactic
wenzelm@51717
    16
  val safe_simp_tac: Proof.context -> int -> tactic
wenzelm@51717
    17
  val safe_asm_simp_tac: Proof.context -> int -> tactic
wenzelm@51717
    18
  val safe_full_simp_tac: Proof.context -> int -> tactic
wenzelm@51717
    19
  val safe_asm_lr_simp_tac: Proof.context -> int -> tactic
wenzelm@51717
    20
  val safe_asm_full_simp_tac: Proof.context -> int -> tactic
wenzelm@51717
    21
  val simplify: Proof.context -> thm -> thm
wenzelm@51717
    22
  val asm_simplify: Proof.context -> thm -> thm
wenzelm@51717
    23
  val full_simplify: Proof.context -> thm -> thm
wenzelm@51717
    24
  val asm_lr_simplify: Proof.context -> thm -> thm
wenzelm@51717
    25
  val asm_full_simplify: Proof.context -> thm -> thm
wenzelm@16014
    26
end;
wenzelm@16014
    27
wenzelm@16014
    28
signature SIMPLIFIER =
wenzelm@16014
    29
sig
wenzelm@16014
    30
  include BASIC_SIMPLIFIER
wenzelm@51717
    31
  val map_ss: (Proof.context -> Proof.context) -> Context.generic -> Context.generic
wenzelm@56510
    32
  val attrib: (thm -> Proof.context -> Proof.context) -> attribute
wenzelm@56510
    33
  val simp_add: attribute
wenzelm@56510
    34
  val simp_del: attribute
wenzelm@56510
    35
  val cong_add: attribute
wenzelm@56510
    36
  val cong_del: attribute
wenzelm@56510
    37
  val check_simproc: Proof.context -> xstring * Position.T -> string
wenzelm@56510
    38
  val the_simproc: Proof.context -> string -> simproc
wenzelm@62913
    39
  type 'a simproc_spec = {lhss: 'a list, proc: morphism -> Proof.context -> cterm -> thm option}
wenzelm@61144
    40
  val make_simproc: Proof.context -> string -> term simproc_spec -> simproc
wenzelm@61144
    41
  val define_simproc: binding -> term simproc_spec -> local_theory -> local_theory
wenzelm@61144
    42
  val define_simproc_cmd: binding -> string simproc_spec -> local_theory -> local_theory
wenzelm@59917
    43
  val pretty_simpset: bool -> Proof.context -> Pretty.T
wenzelm@51717
    44
  val default_mk_sym: Proof.context -> thm -> thm option
wenzelm@51717
    45
  val prems_of: Proof.context -> thm list
wenzelm@51717
    46
  val add_simp: thm -> Proof.context -> Proof.context
wenzelm@51717
    47
  val del_simp: thm -> Proof.context -> Proof.context
wenzelm@63221
    48
  val init_simpset: thm list -> Proof.context -> Proof.context
wenzelm@51717
    49
  val add_eqcong: thm -> Proof.context -> Proof.context
wenzelm@51717
    50
  val del_eqcong: thm -> Proof.context -> Proof.context
wenzelm@51717
    51
  val add_cong: thm -> Proof.context -> Proof.context
wenzelm@51717
    52
  val del_cong: thm -> Proof.context -> Proof.context
wenzelm@51717
    53
  val add_prems: thm list -> Proof.context -> Proof.context
wenzelm@51717
    54
  val mksimps: Proof.context -> thm -> thm list
wenzelm@51717
    55
  val set_mksimps: (Proof.context -> thm -> thm list) -> Proof.context -> Proof.context
wenzelm@51717
    56
  val set_mkcong: (Proof.context -> thm -> thm) -> Proof.context -> Proof.context
wenzelm@51717
    57
  val set_mksym: (Proof.context -> thm -> thm option) -> Proof.context -> Proof.context
wenzelm@51717
    58
  val set_mkeqTrue: (Proof.context -> thm -> thm option) -> Proof.context -> Proof.context
wenzelm@51717
    59
  val set_termless: (term * term -> bool) -> Proof.context -> Proof.context
wenzelm@51717
    60
  val set_subgoaler: (Proof.context -> int -> tactic) -> Proof.context -> Proof.context
wenzelm@54729
    61
  type trace_ops
wenzelm@54731
    62
  val set_trace_ops: trace_ops -> theory -> theory
wenzelm@51717
    63
  val rewrite: Proof.context -> conv
wenzelm@51717
    64
  val asm_rewrite: Proof.context -> conv
wenzelm@51717
    65
  val full_rewrite: Proof.context -> conv
wenzelm@51717
    66
  val asm_lr_rewrite: Proof.context -> conv
wenzelm@51717
    67
  val asm_full_rewrite: Proof.context -> conv
wenzelm@30513
    68
  val cong_modifiers: Method.modifier parser list
wenzelm@30513
    69
  val simp_modifiers': Method.modifier parser list
wenzelm@30513
    70
  val simp_modifiers: Method.modifier parser list
wenzelm@30513
    71
  val method_setup: Method.modifier parser list -> theory -> theory
wenzelm@63532
    72
  val unsafe_solver_tac: Proof.context -> int -> tactic
wenzelm@63532
    73
  val unsafe_solver: solver
wenzelm@63532
    74
  val safe_solver_tac: Proof.context -> int -> tactic
wenzelm@63532
    75
  val safe_solver: solver
wenzelm@16014
    76
end;
wenzelm@16014
    77
wenzelm@16014
    78
structure Simplifier: SIMPLIFIER =
wenzelm@16014
    79
struct
wenzelm@16014
    80
wenzelm@41228
    81
open Raw_Simplifier;
wenzelm@21708
    82
wenzelm@21708
    83
wenzelm@51717
    84
(** declarations **)
wenzelm@16014
    85
wenzelm@26497
    86
(* attributes *)
wenzelm@26497
    87
wenzelm@45620
    88
fun attrib f = Thm.declaration_attribute (map_ss o f);
wenzelm@16014
    89
wenzelm@45620
    90
val simp_add = attrib add_simp;
wenzelm@45620
    91
val simp_del = attrib del_simp;
wenzelm@45620
    92
val cong_add = attrib add_cong;
wenzelm@45620
    93
val cong_del = attrib del_cong;
wenzelm@26497
    94
wenzelm@16014
    95
wenzelm@22201
    96
(** named simprocs **)
wenzelm@22201
    97
wenzelm@51717
    98
structure Simprocs = Generic_Data
wenzelm@51717
    99
(
wenzelm@51717
   100
  type T = simproc Name_Space.table;
wenzelm@51717
   101
  val empty : T = Name_Space.empty_table "simproc";
wenzelm@51717
   102
  val extend = I;
wenzelm@51717
   103
  fun merge data : T = Name_Space.merge_tables data;
wenzelm@51717
   104
);
wenzelm@51717
   105
wenzelm@51717
   106
wenzelm@22204
   107
(* get simprocs *)
wenzelm@22204
   108
wenzelm@51717
   109
val get_simprocs = Simprocs.get o Context.Proof;
wenzelm@51717
   110
wenzelm@47005
   111
fun check_simproc ctxt = Name_Space.check (Context.Proof ctxt) (get_simprocs ctxt) #> #1;
wenzelm@42466
   112
val the_simproc = Name_Space.get o get_simprocs;
wenzelm@42465
   113
wenzelm@53171
   114
val _ = Theory.setup
wenzelm@56204
   115
  (ML_Antiquotation.value @{binding simproc}
wenzelm@53171
   116
    (Args.context -- Scan.lift (Parse.position Args.name)
wenzelm@53171
   117
      >> (fn (ctxt, name) =>
wenzelm@53171
   118
        "Simplifier.the_simproc ML_context " ^ ML_Syntax.print_string (check_simproc ctxt name))));
wenzelm@22204
   119
wenzelm@22204
   120
wenzelm@22204
   121
(* define simprocs *)
wenzelm@22201
   122
wenzelm@62913
   123
type 'a simproc_spec = {lhss: 'a list, proc: morphism -> Proof.context -> cterm -> thm option};
wenzelm@61144
   124
wenzelm@62913
   125
fun make_simproc ctxt name {lhss, proc} =
wenzelm@61144
   126
  let
wenzelm@61144
   127
    val ctxt' = fold Variable.auto_fixes lhss ctxt;
wenzelm@61144
   128
    val lhss' = Variable.export_terms ctxt' ctxt lhss;
wenzelm@61144
   129
  in
wenzelm@62913
   130
    cert_simproc (Proof_Context.theory_of ctxt) name {lhss = lhss', proc = proc}
wenzelm@61144
   131
  end;
wenzelm@61144
   132
wenzelm@22201
   133
local
wenzelm@22201
   134
wenzelm@62913
   135
fun def_simproc prep b {lhss, proc} lthy =
wenzelm@22201
   136
  let
wenzelm@61144
   137
    val simproc =
wenzelm@62913
   138
      make_simproc lthy (Local_Theory.full_name lthy b) {lhss = prep lthy lhss, proc = proc};
wenzelm@22201
   139
  in
wenzelm@61146
   140
    lthy |> Local_Theory.declaration {syntax = false, pervasive = false} (fn phi => fn context =>
wenzelm@22201
   141
      let
haftmann@28991
   142
        val b' = Morphism.binding phi b;
wenzelm@45290
   143
        val simproc' = transform_simproc phi simproc;
wenzelm@22201
   144
      in
wenzelm@42375
   145
        context
wenzelm@51717
   146
        |> Simprocs.map (#2 o Name_Space.define context true (b', simproc'))
wenzelm@51717
   147
        |> map_ss (fn ctxt => ctxt addsimprocs [simproc'])
wenzelm@22201
   148
      end)
wenzelm@22201
   149
  end;
wenzelm@22201
   150
wenzelm@22201
   151
in
wenzelm@22201
   152
wenzelm@61144
   153
val define_simproc = def_simproc Syntax.check_terms;
wenzelm@61144
   154
val define_simproc_cmd = def_simproc Syntax.read_terms;
wenzelm@22201
   155
wenzelm@22201
   156
end;
wenzelm@22201
   157
wenzelm@22201
   158
wenzelm@22201
   159
wenzelm@56510
   160
(** pretty_simpset **)
wenzelm@56510
   161
wenzelm@59917
   162
fun pretty_simpset verbose ctxt =
wenzelm@56510
   163
  let
wenzelm@56510
   164
    val pretty_term = Syntax.pretty_term ctxt;
wenzelm@61268
   165
    val pretty_thm = Thm.pretty_thm ctxt;
wenzelm@61268
   166
    val pretty_thm_item = Thm.pretty_thm_item ctxt;
wenzelm@56510
   167
wenzelm@56510
   168
    fun pretty_simproc (name, lhss) =
wenzelm@56510
   169
      Pretty.block
wenzelm@56510
   170
        (Pretty.mark_str name :: Pretty.str ":" :: Pretty.fbrk ::
wenzelm@61098
   171
          Pretty.fbreaks (map (Pretty.item o single o pretty_term) lhss));
wenzelm@56510
   172
wenzelm@56510
   173
    fun pretty_cong_name (const, name) =
wenzelm@56510
   174
      pretty_term ((if const then Const else Free) (name, dummyT));
wenzelm@56510
   175
    fun pretty_cong (name, thm) =
wenzelm@56510
   176
      Pretty.block [pretty_cong_name name, Pretty.str ":", Pretty.brk 1, pretty_thm thm];
wenzelm@56510
   177
wenzelm@56510
   178
    val {simps, procs, congs, loopers, unsafe_solvers, safe_solvers, ...} =
wenzelm@56510
   179
      dest_ss (simpset_of ctxt);
wenzelm@56510
   180
    val simprocs =
wenzelm@59917
   181
      Name_Space.markup_entries verbose ctxt (Name_Space.space_of_table (get_simprocs ctxt)) procs;
wenzelm@56510
   182
  in
wenzelm@56510
   183
    [Pretty.big_list "simplification rules:" (map (pretty_thm_item o #2) simps),
wenzelm@56510
   184
      Pretty.big_list "simplification procedures:" (map pretty_simproc simprocs),
wenzelm@56510
   185
      Pretty.big_list "congruences:" (map pretty_cong congs),
wenzelm@56510
   186
      Pretty.strs ("loopers:" :: map quote loopers),
wenzelm@56510
   187
      Pretty.strs ("unsafe solvers:" :: map quote unsafe_solvers),
wenzelm@56510
   188
      Pretty.strs ("safe solvers:" :: map quote safe_solvers)]
wenzelm@56510
   189
    |> Pretty.chunks
wenzelm@56510
   190
  end;
wenzelm@56510
   191
wenzelm@56510
   192
wenzelm@56510
   193
wenzelm@17967
   194
(** simplification tactics and rules **)
wenzelm@17967
   195
wenzelm@51717
   196
fun solve_all_tac solvers ctxt =
wenzelm@17967
   197
  let
wenzelm@54728
   198
    val {subgoal_tac, ...} = Raw_Simplifier.internal_ss (simpset_of ctxt);
wenzelm@51717
   199
    val solve_tac = subgoal_tac (Raw_Simplifier.set_solvers solvers ctxt) THEN_ALL_NEW (K no_tac);
wenzelm@17967
   200
  in DEPTH_SOLVE (solve_tac 1) end;
wenzelm@17967
   201
wenzelm@17967
   202
(*NOTE: may instantiate unknowns that appear also in other subgoals*)
wenzelm@51717
   203
fun generic_simp_tac safe mode ctxt =
wenzelm@17967
   204
  let
wenzelm@54728
   205
    val {loop_tacs, solvers = (unsafe_solvers, solvers), ...} =
wenzelm@51717
   206
      Raw_Simplifier.internal_ss (simpset_of ctxt);
wenzelm@51717
   207
    val loop_tac = FIRST' (map (fn (_, tac) => tac ctxt) (rev loop_tacs));
wenzelm@51717
   208
    val solve_tac = FIRST' (map (Raw_Simplifier.solver ctxt)
haftmann@22717
   209
      (rev (if safe then solvers else unsafe_solvers)));
wenzelm@17967
   210
wenzelm@17967
   211
    fun simp_loop_tac i =
wenzelm@51717
   212
      Raw_Simplifier.generic_rewrite_goal_tac mode (solve_all_tac unsafe_solvers) ctxt i THEN
wenzelm@17967
   213
      (solve_tac i ORELSE TRY ((loop_tac THEN_ALL_NEW simp_loop_tac) i));
wenzelm@52458
   214
  in PREFER_GOAL (simp_loop_tac 1) end;
wenzelm@17967
   215
wenzelm@17967
   216
local
wenzelm@17967
   217
wenzelm@51717
   218
fun simp rew mode ctxt thm =
wenzelm@17967
   219
  let
wenzelm@54728
   220
    val {solvers = (unsafe_solvers, _), ...} = Raw_Simplifier.internal_ss (simpset_of ctxt);
haftmann@22717
   221
    val tacf = solve_all_tac (rev unsafe_solvers);
wenzelm@17967
   222
    fun prover s th = Option.map #1 (Seq.pull (tacf s th));
wenzelm@51717
   223
  in rew mode prover ctxt thm end;
wenzelm@17967
   224
wenzelm@17967
   225
in
wenzelm@17967
   226
wenzelm@41228
   227
val simp_thm = simp Raw_Simplifier.rewrite_thm;
wenzelm@41228
   228
val simp_cterm = simp Raw_Simplifier.rewrite_cterm;
wenzelm@17967
   229
wenzelm@17967
   230
end;
wenzelm@17967
   231
wenzelm@17967
   232
wenzelm@16806
   233
(* tactics *)
wenzelm@16806
   234
wenzelm@16014
   235
val simp_tac = generic_simp_tac false (false, false, false);
wenzelm@16014
   236
val asm_simp_tac = generic_simp_tac false (false, true, false);
wenzelm@16014
   237
val full_simp_tac = generic_simp_tac false (true, false, false);
wenzelm@16014
   238
val asm_lr_simp_tac = generic_simp_tac false (true, true, false);
wenzelm@16014
   239
val asm_full_simp_tac = generic_simp_tac false (true, true, true);
wenzelm@50107
   240
wenzelm@50107
   241
(*not totally safe: may instantiate unknowns that appear also in other subgoals*)
wenzelm@50107
   242
val safe_simp_tac = generic_simp_tac true (false, false, false);
wenzelm@50107
   243
val safe_asm_simp_tac = generic_simp_tac true (false, true, false);
wenzelm@50107
   244
val safe_full_simp_tac = generic_simp_tac true (true, false, false);
wenzelm@50107
   245
val safe_asm_lr_simp_tac = generic_simp_tac true (true, true, false);
wenzelm@16014
   246
val safe_asm_full_simp_tac = generic_simp_tac true (true, true, true);
wenzelm@16014
   247
wenzelm@16806
   248
wenzelm@16806
   249
(* conversions *)
wenzelm@16806
   250
wenzelm@17967
   251
val          simplify = simp_thm (false, false, false);
wenzelm@17967
   252
val      asm_simplify = simp_thm (false, true, false);
wenzelm@17967
   253
val     full_simplify = simp_thm (true, false, false);
wenzelm@17967
   254
val   asm_lr_simplify = simp_thm (true, true, false);
wenzelm@17967
   255
val asm_full_simplify = simp_thm (true, true, true);
wenzelm@16014
   256
wenzelm@17967
   257
val          rewrite = simp_cterm (false, false, false);
wenzelm@17967
   258
val      asm_rewrite = simp_cterm (false, true, false);
wenzelm@17967
   259
val     full_rewrite = simp_cterm (true, false, false);
wenzelm@17967
   260
val   asm_lr_rewrite = simp_cterm (true, true, false);
wenzelm@17967
   261
val asm_full_rewrite = simp_cterm (true, true, true);
wenzelm@16014
   262
wenzelm@16014
   263
wenzelm@16014
   264
wenzelm@16014
   265
(** concrete syntax of attributes **)
wenzelm@16014
   266
wenzelm@16014
   267
(* add / del *)
wenzelm@16014
   268
wenzelm@16014
   269
val simpN = "simp";
wenzelm@16014
   270
val congN = "cong";
wenzelm@16014
   271
val onlyN = "only";
wenzelm@16014
   272
val no_asmN = "no_asm";
wenzelm@16014
   273
val no_asm_useN = "no_asm_use";
wenzelm@16014
   274
val no_asm_simpN = "no_asm_simp";
wenzelm@16014
   275
val asm_lrN = "asm_lr";
wenzelm@16014
   276
wenzelm@16014
   277
wenzelm@24024
   278
(* simprocs *)
wenzelm@24024
   279
wenzelm@24024
   280
local
wenzelm@24024
   281
wenzelm@24024
   282
val add_del =
wenzelm@24024
   283
  (Args.del -- Args.colon >> K (op delsimprocs) ||
wenzelm@24024
   284
    Scan.option (Args.add -- Args.colon) >> K (op addsimprocs))
wenzelm@24024
   285
  >> (fn f => fn simproc => fn phi => Thm.declaration_attribute
wenzelm@51717
   286
      (K (Raw_Simplifier.map_ss (fn ctxt => f (ctxt, [transform_simproc phi simproc])))));
wenzelm@24024
   287
wenzelm@24024
   288
in
wenzelm@24024
   289
wenzelm@30528
   290
val simproc_att =
wenzelm@42465
   291
  (Args.context -- Scan.lift add_del) :|-- (fn (ctxt, decl) =>
wenzelm@42465
   292
    Scan.repeat1 (Scan.lift (Args.named_attribute (decl o the_simproc ctxt o check_simproc ctxt))))
wenzelm@45375
   293
  >> (fn atts => Thm.declaration_attribute (fn th =>
wenzelm@46776
   294
        fold (fn att => Thm.attribute_declaration (Morphism.form att) th) atts));
wenzelm@24024
   295
wenzelm@24024
   296
end;
wenzelm@24124
   297
wenzelm@24024
   298
wenzelm@16014
   299
(* conversions *)
wenzelm@16014
   300
wenzelm@16014
   301
local
wenzelm@16014
   302
wenzelm@16014
   303
fun conv_mode x =
wenzelm@16014
   304
  ((Args.parens (Args.$$$ no_asmN) >> K simplify ||
wenzelm@16014
   305
    Args.parens (Args.$$$ no_asm_simpN) >> K asm_simplify ||
wenzelm@16014
   306
    Args.parens (Args.$$$ no_asm_useN) >> K full_simplify ||
wenzelm@16014
   307
    Scan.succeed asm_full_simplify) |> Scan.lift) x;
wenzelm@16014
   308
wenzelm@16014
   309
in
wenzelm@16014
   310
wenzelm@30528
   311
val simplified = conv_mode -- Attrib.thms >>
wenzelm@61853
   312
  (fn (f, ths) => Thm.rule_attribute ths (fn context =>
wenzelm@51717
   313
    f ((if null ths then I else Raw_Simplifier.clear_simpset)
wenzelm@51717
   314
        (Context.proof_of context) addsimps ths)));
wenzelm@16014
   315
wenzelm@16014
   316
end;
wenzelm@16014
   317
wenzelm@16014
   318
wenzelm@16014
   319
(* setup attributes *)
wenzelm@16014
   320
wenzelm@53171
   321
val _ = Theory.setup
wenzelm@56204
   322
 (Attrib.setup @{binding simp} (Attrib.add_del simp_add simp_del)
wenzelm@30528
   323
    "declaration of Simplifier rewrite rule" #>
wenzelm@56204
   324
  Attrib.setup @{binding cong} (Attrib.add_del cong_add cong_del)
wenzelm@30528
   325
    "declaration of Simplifier congruence rule" #>
wenzelm@56204
   326
  Attrib.setup @{binding simproc} simproc_att
wenzelm@33671
   327
    "declaration of simplification procedures" #>
wenzelm@56204
   328
  Attrib.setup @{binding simplified} simplified "simplified rule");
wenzelm@16014
   329
wenzelm@16014
   330
wenzelm@16014
   331
wenzelm@31300
   332
(** method syntax **)
wenzelm@16014
   333
wenzelm@16014
   334
val cong_modifiers =
wenzelm@64556
   335
 [Args.$$$ congN -- Args.colon >> K (Method.modifier cong_add \<^here>),
wenzelm@64556
   336
  Args.$$$ congN -- Args.add -- Args.colon >> K (Method.modifier cong_add \<^here>),
wenzelm@64556
   337
  Args.$$$ congN -- Args.del -- Args.colon >> K (Method.modifier cong_del \<^here>)];
wenzelm@16014
   338
wenzelm@16014
   339
val simp_modifiers =
wenzelm@64556
   340
 [Args.$$$ simpN -- Args.colon >> K (Method.modifier simp_add \<^here>),
wenzelm@64556
   341
  Args.$$$ simpN -- Args.add -- Args.colon >> K (Method.modifier simp_add \<^here>),
wenzelm@64556
   342
  Args.$$$ simpN -- Args.del -- Args.colon >> K (Method.modifier simp_del \<^here>),
wenzelm@58048
   343
  Args.$$$ simpN -- Args.$$$ onlyN -- Args.colon >>
wenzelm@64556
   344
    K {init = Raw_Simplifier.clear_simpset, attribute = simp_add, pos = \<^here>}]
wenzelm@16014
   345
   @ cong_modifiers;
wenzelm@16014
   346
wenzelm@16014
   347
val simp_modifiers' =
wenzelm@64556
   348
 [Args.add -- Args.colon >> K (Method.modifier simp_add \<^here>),
wenzelm@64556
   349
  Args.del -- Args.colon >> K (Method.modifier simp_del \<^here>),
wenzelm@58048
   350
  Args.$$$ onlyN -- Args.colon >>
wenzelm@64556
   351
    K {init = Raw_Simplifier.clear_simpset, attribute = simp_add, pos = \<^here>}]
wenzelm@16014
   352
   @ cong_modifiers;
wenzelm@16014
   353
wenzelm@31300
   354
val simp_options =
wenzelm@31300
   355
 (Args.parens (Args.$$$ no_asmN) >> K simp_tac ||
wenzelm@31300
   356
  Args.parens (Args.$$$ no_asm_simpN) >> K asm_simp_tac ||
wenzelm@31300
   357
  Args.parens (Args.$$$ no_asm_useN) >> K full_simp_tac ||
wenzelm@31300
   358
  Args.parens (Args.$$$ asm_lrN) >> K asm_lr_simp_tac ||
wenzelm@31300
   359
  Scan.succeed asm_full_simp_tac);
wenzelm@16014
   360
wenzelm@31300
   361
fun simp_method more_mods meth =
wenzelm@35613
   362
  Scan.lift simp_options --|
wenzelm@31300
   363
    Method.sections (more_mods @ simp_modifiers') >>
wenzelm@35613
   364
    (fn tac => fn ctxt => METHOD (fn facts => meth ctxt tac facts));
wenzelm@16014
   365
wenzelm@16014
   366
wenzelm@16014
   367
wenzelm@18708
   368
(** setup **)
wenzelm@18708
   369
wenzelm@31300
   370
fun method_setup more_mods =
wenzelm@56204
   371
  Method.setup @{binding simp}
wenzelm@31300
   372
    (simp_method more_mods (fn ctxt => fn tac => fn facts =>
wenzelm@61841
   373
      HEADGOAL (Method.insert_tac ctxt facts THEN'
wenzelm@51717
   374
        (CHANGED_PROP oo tac) ctxt)))
wenzelm@31300
   375
    "simplification" #>
wenzelm@56204
   376
  Method.setup @{binding simp_all}
wenzelm@31300
   377
    (simp_method more_mods (fn ctxt => fn tac => fn facts =>
wenzelm@61841
   378
      ALLGOALS (Method.insert_tac ctxt facts) THEN
wenzelm@58008
   379
        (CHANGED_PROP o PARALLEL_ALLGOALS o tac) ctxt))
wenzelm@31300
   380
    "simplification (all goals)";
wenzelm@16014
   381
wenzelm@63532
   382
fun unsafe_solver_tac ctxt =
wenzelm@63532
   383
  FIRST' [resolve_tac ctxt (Drule.reflexive_thm :: Raw_Simplifier.prems_of ctxt), assume_tac ctxt];
wenzelm@63532
   384
val unsafe_solver = mk_solver "Pure unsafe" unsafe_solver_tac;
wenzelm@16014
   385
wenzelm@63532
   386
(*no premature instantiation of variables during simplification*)
wenzelm@63532
   387
fun safe_solver_tac ctxt =
wenzelm@63532
   388
  FIRST' [match_tac ctxt (Drule.reflexive_thm :: Raw_Simplifier.prems_of ctxt), eq_assume_tac];
wenzelm@63532
   389
val safe_solver = mk_solver "Pure safe" safe_solver_tac;
wenzelm@16014
   390
wenzelm@63532
   391
val _ =
wenzelm@63532
   392
  Theory.setup
wenzelm@63532
   393
    (method_setup [] #> Context.theory_map (map_ss (fn ctxt =>
wenzelm@63532
   394
      empty_simpset ctxt
wenzelm@63532
   395
      setSSolver safe_solver
wenzelm@63532
   396
      setSolver unsafe_solver
wenzelm@63532
   397
      |> set_subgoaler asm_simp_tac)));
wenzelm@16014
   398
wenzelm@16014
   399
end;
wenzelm@16014
   400
wenzelm@32738
   401
structure Basic_Simplifier: BASIC_SIMPLIFIER = Simplifier;
wenzelm@32738
   402
open Basic_Simplifier;