src/Pure/simplifier.ML
author blanchet
Mon, 06 Dec 2010 13:29:23 +0100
changeset 40996 63112be4a469
parent 38715 6513ea67d95d
child 41226 adcb9a1198e7
permissions -rw-r--r--
added "Neq" operator to monotonicity inference module
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/simplifier.ML
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     2
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     3
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     4
Generic simplifier, suitable for most logics (see also
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     5
meta_simplifier.ML for the actual meta-level rewriting engine).
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     6
*)
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     7
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     8
signature BASIC_SIMPLIFIER =
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     9
sig
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    10
  include BASIC_META_SIMPLIFIER
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
    11
  val change_simpset: (simpset -> simpset) -> unit
32148
253f6808dabe renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents: 32091
diff changeset
    12
  val global_simpset_of: theory -> simpset
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    13
  val Addsimprocs: simproc list -> unit
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    14
  val Delsimprocs: simproc list -> unit
32148
253f6808dabe renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents: 32091
diff changeset
    15
  val simpset_of: Proof.context -> simpset
17967
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
    16
  val generic_simp_tac: bool -> bool * bool * bool -> simpset -> int -> tactic
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    17
  val safe_asm_full_simp_tac: simpset -> int -> tactic
35613
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
    18
  val simp_tac: simpset -> int -> tactic
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
    19
  val asm_simp_tac: simpset -> int -> tactic
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
    20
  val full_simp_tac: simpset -> int -> tactic
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
    21
  val asm_lr_simp_tac: simpset -> int -> tactic
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
    22
  val asm_full_simp_tac: simpset -> int -> tactic
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
    23
  val simplify: simpset -> thm -> thm
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
    24
  val asm_simplify: simpset -> thm -> thm
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
    25
  val full_simplify: simpset -> thm -> thm
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
    26
  val asm_lr_simplify: simpset -> thm -> thm
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    27
  val asm_full_simplify: simpset -> thm -> thm
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    28
end;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    29
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    30
signature SIMPLIFIER =
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    31
sig
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    32
  include BASIC_SIMPLIFIER
30356
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    33
  val pretty_ss: Proof.context -> simpset -> Pretty.T
17004
6a0d8ecf65f1 export clear_ss;
wenzelm
parents: 16989
diff changeset
    34
  val clear_ss: simpset -> simpset
32738
15bb09ca0378 explicit indication of Unsynchronized.ref;
wenzelm
parents: 32148
diff changeset
    35
  val debug_bounds: bool Unsynchronized.ref
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
    36
  val inherit_context: simpset -> simpset -> simpset
17898
ff78ecd1e768 renamed set_context to context;
wenzelm
parents: 17883
diff changeset
    37
  val the_context: simpset -> Proof.context
ff78ecd1e768 renamed set_context to context;
wenzelm
parents: 17883
diff changeset
    38
  val context: Proof.context -> simpset -> simpset
37441
69ba3f21c295 tuned whitespace
haftmann
parents: 37216
diff changeset
    39
  val global_context: theory -> simpset -> simpset
36600
62d43ca574d0 export Simplifier.with_context;
wenzelm
parents: 36545
diff changeset
    40
  val with_context: Proof.context -> (simpset -> simpset) -> simpset -> simpset
38715
6513ea67d95d renamed Simplifier.simproc(_i) to Simplifier.simproc_global(_i) to emphasize that this is not the real thing;
wenzelm
parents: 37441
diff changeset
    41
  val simproc_global_i: theory -> string -> term list
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16014
diff changeset
    42
    -> (theory -> simpset -> term -> thm option) -> simproc
38715
6513ea67d95d renamed Simplifier.simproc(_i) to Simplifier.simproc_global(_i) to emphasize that this is not the real thing;
wenzelm
parents: 37441
diff changeset
    43
  val simproc_global: theory -> string -> string list
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16014
diff changeset
    44
    -> (theory -> simpset -> term -> thm option) -> simproc
35613
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
    45
  val rewrite: simpset -> conv
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
    46
  val asm_rewrite: simpset -> conv
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
    47
  val full_rewrite: simpset -> conv
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
    48
  val asm_lr_rewrite: simpset -> conv
23598
wenzelm
parents: 23536
diff changeset
    49
  val asm_full_rewrite: simpset -> conv
22379
abfcb9899d41 exported get_ss, map_ss;
wenzelm
parents: 22236
diff changeset
    50
  val get_ss: Context.generic -> simpset
abfcb9899d41 exported get_ss, map_ss;
wenzelm
parents: 22236
diff changeset
    51
  val map_ss: (simpset -> simpset) -> Context.generic -> Context.generic
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    52
  val attrib: (simpset * thm list -> simpset) -> attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    53
  val simp_add: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    54
  val simp_del: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    55
  val cong_add: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    56
  val cong_del: attribute
26497
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
    57
  val map_simpset: (simpset -> simpset) -> theory -> theory
24024
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
    58
  val get_simproc: Context.generic -> xstring -> simproc
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
    59
  val def_simproc: {name: string, lhss: string list,
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
    60
    proc: morphism -> simpset -> cterm -> thm option, identifier: thm list} ->
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
    61
    local_theory -> local_theory
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
    62
  val def_simproc_i: {name: string, lhss: term list,
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
    63
    proc: morphism -> simpset -> cterm -> thm option, identifier: thm list} ->
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
    64
    local_theory -> local_theory
30513
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30510
diff changeset
    65
  val cong_modifiers: Method.modifier parser list
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30510
diff changeset
    66
  val simp_modifiers': Method.modifier parser list
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30510
diff changeset
    67
  val simp_modifiers: Method.modifier parser list
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30510
diff changeset
    68
  val method_setup: Method.modifier parser list -> theory -> theory
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
    69
  val easy_setup: thm -> thm list -> theory -> theory
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    70
end;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    71
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    72
structure Simplifier: SIMPLIFIER =
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    73
struct
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    74
21708
45e7491bea47 reorganized structure Tactic vs. MetaSimplifier;
wenzelm
parents: 21687
diff changeset
    75
open MetaSimplifier;
45e7491bea47 reorganized structure Tactic vs. MetaSimplifier;
wenzelm
parents: 21687
diff changeset
    76
45e7491bea47 reorganized structure Tactic vs. MetaSimplifier;
wenzelm
parents: 21687
diff changeset
    77
30356
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    78
(** pretty printing **)
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    79
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    80
fun pretty_ss ctxt ss =
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    81
  let
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    82
    val pretty_cterm = Syntax.pretty_term ctxt o Thm.term_of;
32091
30e2ffbba718 proper context for Display.pretty_thm etc. or old-style versions Display.pretty_thm_global, Display.pretty_thm_without_context etc.;
wenzelm
parents: 31300
diff changeset
    83
    val pretty_thm = Display.pretty_thm ctxt;
30356
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    84
    fun pretty_proc (name, lhss) = Pretty.big_list (name ^ ":") (map pretty_cterm lhss);
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    85
    fun pretty_cong (name, thm) =
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    86
      Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 1, pretty_thm thm];
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    87
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    88
    val {simps, procs, congs, loopers, unsafe_solvers, safe_solvers, ...} = dest_ss ss;
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    89
  in
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    90
    [Pretty.big_list "simplification rules:" (map (pretty_thm o #2) simps),
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    91
      Pretty.big_list "simplification procedures:" (map pretty_proc (sort_wrt #1 procs)),
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    92
      Pretty.big_list "congruences:" (map pretty_cong congs),
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    93
      Pretty.strs ("loopers:" :: map quote loopers),
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    94
      Pretty.strs ("unsafe solvers:" :: map quote unsafe_solvers),
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    95
      Pretty.strs ("safe solvers:" :: map quote safe_solvers)]
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    96
    |> Pretty.chunks
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    97
  end;
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    98
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
    99
36d0e00af606 added dest_ss;
wenzelm
parents: 30336
diff changeset
   100
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   101
(** simpset data **)
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   102
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36610
diff changeset
   103
structure Simpset = Generic_Data
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22770
diff changeset
   104
(
26497
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   105
  type T = simpset;
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   106
  val empty = empty_ss;
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   107
  fun extend ss = MetaSimplifier.inherit_context empty_ss ss;
33519
e31a85f92ce9 adapted Generic_Data, Proof_Data;
wenzelm
parents: 33457
diff changeset
   108
  val merge = merge_ss;
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22770
diff changeset
   109
);
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   110
37216
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36610
diff changeset
   111
val get_ss = Simpset.get;
3165bc303f66 modernized some structure names, keeping a few legacy aliases;
wenzelm
parents: 36610
diff changeset
   112
fun map_ss f context = Simpset.map (with_context (Context.proof_of context) f) context;
26497
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   113
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   114
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   115
(* attributes *)
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   116
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   117
fun attrib f = Thm.declaration_attribute (fn th => map_ss (fn ss => f (ss, [th])));
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   118
26497
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   119
val simp_add = attrib (op addsimps);
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   120
val simp_del = attrib (op delsimps);
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   121
val cong_add = attrib (op addcongs);
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   122
val cong_del = attrib (op delcongs);
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   123
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   124
26497
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   125
(* global simpset *)
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   126
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   127
fun map_simpset f = Context.theory_map (map_ss f);
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   128
fun change_simpset f = Context.>> (Context.map_theory (map_simpset f));
32148
253f6808dabe renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents: 32091
diff changeset
   129
fun global_simpset_of thy =
36610
bafd82950e24 renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents: 36600
diff changeset
   130
  MetaSimplifier.context (ProofContext.init_global thy) (get_ss (Context.Theory thy));
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   131
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   132
fun Addsimprocs args = change_simpset (fn ss => ss addsimprocs args);
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   133
fun Delsimprocs args = change_simpset (fn ss => ss delsimprocs args);
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   134
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   135
26497
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   136
(* local simpset *)
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   137
32148
253f6808dabe renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents: 32091
diff changeset
   138
fun simpset_of ctxt = MetaSimplifier.context ctxt (get_ss (Context.Proof ctxt));
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   139
27338
2cd6c60cc10b ML_Antiquote.value;
wenzelm
parents: 27021
diff changeset
   140
val _ = ML_Antiquote.value "simpset"
32148
253f6808dabe renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents: 32091
diff changeset
   141
  (Scan.succeed "Simplifier.simpset_of (ML_Context.the_local_context ())");
22132
0f26cd597193 added @{simpset};
wenzelm
parents: 22095
diff changeset
   142
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   143
17967
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   144
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   145
(** named simprocs **)
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   146
22204
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   147
(* data *)
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   148
33519
e31a85f92ce9 adapted Generic_Data, Proof_Data;
wenzelm
parents: 33457
diff changeset
   149
structure Simprocs = Generic_Data
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   150
(
33095
bbd52d2f8696 renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents: 33092
diff changeset
   151
  type T = simproc Name_Space.table;
33159
369da293bbd4 make SML/NJ happy;
wenzelm
parents: 33096
diff changeset
   152
  val empty : T = Name_Space.empty_table "simproc";
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   153
  val extend = I;
33519
e31a85f92ce9 adapted Generic_Data, Proof_Data;
wenzelm
parents: 33457
diff changeset
   154
  fun merge simprocs = Name_Space.merge_tables simprocs;
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   155
);
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   156
22204
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   157
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   158
(* get simprocs *)
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   159
24024
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   160
fun get_simproc context xname =
22204
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   161
  let
24024
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   162
    val (space, tab) = Simprocs.get context;
33095
bbd52d2f8696 renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents: 33092
diff changeset
   163
    val name = Name_Space.intern space xname;
22204
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   164
  in
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   165
    (case Symtab.lookup tab name of
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   166
      SOME proc => proc
22204
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   167
    | NONE => error ("Undefined simplification procedure: " ^ quote name))
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   168
  end;
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   169
27338
2cd6c60cc10b ML_Antiquote.value;
wenzelm
parents: 27021
diff changeset
   170
val _ = ML_Antiquote.value "simproc" (Scan.lift Args.name >> (fn name =>
2cd6c60cc10b ML_Antiquote.value;
wenzelm
parents: 27021
diff changeset
   171
  "Simplifier.get_simproc (ML_Context.the_generic_context ()) " ^ ML_Syntax.print_string name));
22204
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   172
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   173
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   174
(* define simprocs *)
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   175
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   176
local
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   177
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   178
fun gen_simproc prep {name, lhss, proc, identifier} lthy =
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   179
  let
28991
694227dd3e8c dropped NameSpace.declare_base
haftmann
parents: 28965
diff changeset
   180
    val b = Binding.name name;
33671
4b0f2599ed48 modernized structure Local_Theory;
wenzelm
parents: 33551
diff changeset
   181
    val naming = Local_Theory.naming_of lthy;
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   182
    val simproc = make_simproc
33169
3012726e9929 LocalTheory.naming_of;
wenzelm
parents: 33159
diff changeset
   183
      {name = Name_Space.full_name naming b,
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   184
       lhss =
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   185
        let
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   186
          val lhss' = prep lthy lhss;
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   187
          val ctxt' = lthy
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   188
            |> fold Variable.declare_term lhss'
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   189
            |> fold Variable.auto_fixes lhss';
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   190
        in Variable.export_terms ctxt' lthy lhss' end
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   191
        |> map (Thm.cterm_of (ProofContext.theory_of lthy)),
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   192
       proc = proc,
33551
c40ced05b10a define simprocs: do not apply target_morphism prematurely, this is already done in LocalTheory.declaration;
wenzelm
parents: 33519
diff changeset
   193
       identifier = identifier};
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   194
  in
33671
4b0f2599ed48 modernized structure Local_Theory;
wenzelm
parents: 33551
diff changeset
   195
    lthy |> Local_Theory.declaration false (fn phi =>
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   196
      let
28991
694227dd3e8c dropped NameSpace.declare_base
haftmann
parents: 28965
diff changeset
   197
        val b' = Morphism.binding phi b;
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   198
        val simproc' = morph_simproc phi simproc;
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   199
      in
33095
bbd52d2f8696 renamed NameSpace to Name_Space -- also to emphasize its subtle change in semantics;
wenzelm
parents: 33092
diff changeset
   200
        Simprocs.map (#2 o Name_Space.define true naming (b', simproc'))
24024
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   201
        #> map_ss (fn ss => ss addsimprocs [simproc'])
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   202
      end)
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   203
  end;
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   204
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   205
in
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   206
24509
23ee6b7788c2 replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents: 24124
diff changeset
   207
val def_simproc = gen_simproc Syntax.read_terms;
23ee6b7788c2 replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents: 24124
diff changeset
   208
val def_simproc_i = gen_simproc Syntax.check_terms;
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   209
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   210
end;
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   211
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   212
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   213
17967
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   214
(** simplification tactics and rules **)
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   215
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   216
fun solve_all_tac solvers ss =
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   217
  let
30336
efd1bec4630a renamed rep_ss to MetaSimplifier.internal_ss;
wenzelm
parents: 29606
diff changeset
   218
    val (_, {subgoal_tac, ...}) = MetaSimplifier.internal_ss ss;
17967
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   219
    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: 17898
diff changeset
   220
  in DEPTH_SOLVE (solve_tac 1) end;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   221
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   222
(*NOTE: may instantiate unknowns that appear also in other subgoals*)
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   223
fun generic_simp_tac safe mode ss =
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   224
  let
30336
efd1bec4630a renamed rep_ss to MetaSimplifier.internal_ss;
wenzelm
parents: 29606
diff changeset
   225
    val (_, {loop_tacs, solvers = (unsafe_solvers, solvers), ...}) = MetaSimplifier.internal_ss ss;
21286
b5e7b80caa6a introduces canonical AList functions for loop_tacs
haftmann
parents: 20872
diff changeset
   226
    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: 17898
diff changeset
   227
    val solve_tac = FIRST' (map (MetaSimplifier.solver ss)
22717
74dbc7696083 canonical merge operations
haftmann
parents: 22709
diff changeset
   228
      (rev (if safe then solvers else unsafe_solvers)));
17967
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   229
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   230
    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: 23086
diff changeset
   231
      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: 17898
diff changeset
   232
      (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: 17898
diff changeset
   233
  in simp_loop_tac end;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   234
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   235
local
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   236
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   237
fun simp rew mode ss thm =
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   238
  let
30336
efd1bec4630a renamed rep_ss to MetaSimplifier.internal_ss;
wenzelm
parents: 29606
diff changeset
   239
    val (_, {solvers = (unsafe_solvers, _), ...}) = MetaSimplifier.internal_ss ss;
22717
74dbc7696083 canonical merge operations
haftmann
parents: 22709
diff changeset
   240
    val tacf = solve_all_tac (rev unsafe_solvers);
17967
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   241
    fun prover s th = Option.map #1 (Seq.pull (tacf s th));
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   242
  in rew mode prover ss thm end;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   243
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   244
in
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   245
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   246
val simp_thm = simp MetaSimplifier.rewrite_thm;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   247
val simp_cterm = simp MetaSimplifier.rewrite_cterm;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   248
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   249
end;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   250
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   251
16806
916387f7afd2 removed obsolete delta stuff;
wenzelm
parents: 16709
diff changeset
   252
(* tactics *)
916387f7afd2 removed obsolete delta stuff;
wenzelm
parents: 16709
diff changeset
   253
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   254
val simp_tac = generic_simp_tac false (false, false, false);
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   255
val asm_simp_tac = generic_simp_tac false (false, true, false);
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   256
val full_simp_tac = generic_simp_tac false (true, false, false);
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   257
val asm_lr_simp_tac = generic_simp_tac false (true, true, false);
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   258
val asm_full_simp_tac = generic_simp_tac false (true, true, true);
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   259
val safe_asm_full_simp_tac = generic_simp_tac true (true, true, true);
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   260
16806
916387f7afd2 removed obsolete delta stuff;
wenzelm
parents: 16709
diff changeset
   261
916387f7afd2 removed obsolete delta stuff;
wenzelm
parents: 16709
diff changeset
   262
(* conversions *)
916387f7afd2 removed obsolete delta stuff;
wenzelm
parents: 16709
diff changeset
   263
17967
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   264
val          simplify = simp_thm (false, false, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   265
val      asm_simplify = simp_thm (false, true, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   266
val     full_simplify = simp_thm (true, false, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   267
val   asm_lr_simplify = simp_thm (true, true, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   268
val asm_full_simplify = simp_thm (true, true, true);
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   269
17967
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   270
val          rewrite = simp_cterm (false, false, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   271
val      asm_rewrite = simp_cterm (false, true, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   272
val     full_rewrite = simp_cterm (true, false, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   273
val   asm_lr_rewrite = simp_cterm (true, true, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   274
val asm_full_rewrite = simp_cterm (true, true, true);
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   275
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   276
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   277
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   278
(** concrete syntax of attributes **)
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   279
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   280
(* add / del *)
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   281
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   282
val simpN = "simp";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   283
val congN = "cong";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   284
val onlyN = "only";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   285
val no_asmN = "no_asm";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   286
val no_asm_useN = "no_asm_use";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   287
val no_asm_simpN = "no_asm_simp";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   288
val asm_lrN = "asm_lr";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   289
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   290
24024
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   291
(* simprocs *)
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   292
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   293
local
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   294
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   295
val add_del =
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   296
  (Args.del -- Args.colon >> K (op delsimprocs) ||
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   297
    Scan.option (Args.add -- Args.colon) >> K (op addsimprocs))
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   298
  >> (fn f => fn simproc => fn phi => Thm.declaration_attribute
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   299
      (K (map_ss (fn ss => f (ss, [morph_simproc phi simproc])))));
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   300
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   301
in
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   302
30528
7173bf123335 simplified attribute setup;
wenzelm
parents: 30513
diff changeset
   303
val simproc_att =
7173bf123335 simplified attribute setup;
wenzelm
parents: 30513
diff changeset
   304
  Scan.peek (fn context =>
24024
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   305
    add_del :|-- (fn decl =>
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   306
      Scan.repeat1 (Args.named_attribute (decl o get_simproc context))
30528
7173bf123335 simplified attribute setup;
wenzelm
parents: 30513
diff changeset
   307
      >> (Library.apply o map Morphism.form)));
24024
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   308
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   309
end;
24124
4399175e3014 turned simp_depth_limit into configuration option;
wenzelm
parents: 24024
diff changeset
   310
24024
c46bd50df3f9 added attribute "simproc";
wenzelm
parents: 23655
diff changeset
   311
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   312
(* conversions *)
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   313
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   314
local
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   315
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   316
fun conv_mode x =
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   317
  ((Args.parens (Args.$$$ no_asmN) >> K simplify ||
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   318
    Args.parens (Args.$$$ no_asm_simpN) >> K asm_simplify ||
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   319
    Args.parens (Args.$$$ no_asm_useN) >> K full_simplify ||
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   320
    Scan.succeed asm_full_simplify) |> Scan.lift) x;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   321
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   322
in
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   323
30528
7173bf123335 simplified attribute setup;
wenzelm
parents: 30513
diff changeset
   324
val simplified = conv_mode -- Attrib.thms >>
7173bf123335 simplified attribute setup;
wenzelm
parents: 30513
diff changeset
   325
  (fn (f, ths) => Thm.rule_attribute (fn context =>
27021
4593b9f4ba42 proper context for attribute simplified;
wenzelm
parents: 26653
diff changeset
   326
    f ((if null ths then I else MetaSimplifier.clear_ss)
32148
253f6808dabe renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents: 32091
diff changeset
   327
        (simpset_of (Context.proof_of context)) addsimps ths)));
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   328
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   329
end;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   330
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   331
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   332
(* setup attributes *)
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   333
26463
9283b4185fdf Context.>> : operate on Context.generic;
wenzelm
parents: 26435
diff changeset
   334
val _ = Context.>> (Context.map_theory
30528
7173bf123335 simplified attribute setup;
wenzelm
parents: 30513
diff changeset
   335
 (Attrib.setup (Binding.name simpN) (Attrib.add_del simp_add simp_del)
7173bf123335 simplified attribute setup;
wenzelm
parents: 30513
diff changeset
   336
    "declaration of Simplifier rewrite rule" #>
7173bf123335 simplified attribute setup;
wenzelm
parents: 30513
diff changeset
   337
  Attrib.setup (Binding.name congN) (Attrib.add_del cong_add cong_del)
7173bf123335 simplified attribute setup;
wenzelm
parents: 30513
diff changeset
   338
    "declaration of Simplifier congruence rule" #>
33671
4b0f2599ed48 modernized structure Local_Theory;
wenzelm
parents: 33551
diff changeset
   339
  Attrib.setup (Binding.name "simproc") simproc_att
4b0f2599ed48 modernized structure Local_Theory;
wenzelm
parents: 33551
diff changeset
   340
    "declaration of simplification procedures" #>
30528
7173bf123335 simplified attribute setup;
wenzelm
parents: 30513
diff changeset
   341
  Attrib.setup (Binding.name "simplified") simplified "simplified rule"));
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   342
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   343
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   344
31300
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   345
(** method syntax **)
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   346
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   347
val cong_modifiers =
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   348
 [Args.$$$ congN -- Args.colon >> K ((I, cong_add): Method.modifier),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   349
  Args.$$$ congN -- Args.add -- Args.colon >> K (I, cong_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   350
  Args.$$$ congN -- Args.del -- Args.colon >> K (I, cong_del)];
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   351
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   352
val simp_modifiers =
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   353
 [Args.$$$ simpN -- Args.colon >> K (I, simp_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   354
  Args.$$$ simpN -- Args.add -- Args.colon >> K (I, simp_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   355
  Args.$$$ simpN -- Args.del -- Args.colon >> K (I, simp_del),
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   356
  Args.$$$ simpN -- Args.$$$ onlyN -- Args.colon
26497
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   357
    >> K (Context.proof_map (map_ss MetaSimplifier.clear_ss), simp_add)]
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   358
   @ cong_modifiers;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   359
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   360
val simp_modifiers' =
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   361
 [Args.add -- Args.colon >> K (I, simp_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   362
  Args.del -- Args.colon >> K (I, simp_del),
18688
abf0f018b5ec generic attributes;
wenzelm
parents: 18629
diff changeset
   363
  Args.$$$ onlyN -- Args.colon
26497
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   364
    >> K (Context.proof_map (map_ss MetaSimplifier.clear_ss), simp_add)]
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   365
   @ cong_modifiers;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   366
31300
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   367
val simp_options =
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   368
 (Args.parens (Args.$$$ no_asmN) >> K simp_tac ||
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   369
  Args.parens (Args.$$$ no_asm_simpN) >> K asm_simp_tac ||
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   370
  Args.parens (Args.$$$ no_asm_useN) >> K full_simp_tac ||
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   371
  Args.parens (Args.$$$ asm_lrN) >> K asm_lr_simp_tac ||
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   372
  Scan.succeed asm_full_simp_tac);
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   373
31300
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   374
fun simp_method more_mods meth =
35613
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
   375
  Scan.lift simp_options --|
31300
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   376
    Method.sections (more_mods @ simp_modifiers') >>
35613
9d3ff36ad4e1 eliminated Args.bang_facts (legacy feature);
wenzelm
parents: 35232
diff changeset
   377
    (fn tac => fn ctxt => METHOD (fn facts => meth ctxt tac facts));
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   378
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   379
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   380
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   381
(** setup **)
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   382
31300
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   383
fun method_setup more_mods =
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   384
  Method.setup (Binding.name simpN)
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   385
    (simp_method more_mods (fn ctxt => fn tac => fn facts =>
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   386
      HEADGOAL (Method.insert_tac facts THEN'
32148
253f6808dabe renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents: 32091
diff changeset
   387
        (CHANGED_PROP oo tac) (simpset_of ctxt))))
31300
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   388
    "simplification" #>
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   389
  Method.setup (Binding.name "simp_all")
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   390
    (simp_method more_mods (fn ctxt => fn tac => fn facts =>
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   391
      ALLGOALS (Method.insert_tac facts) THEN
32148
253f6808dabe renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents: 32091
diff changeset
   392
        (CHANGED_PROP o ALLGOALS o tac) (simpset_of ctxt)))
31300
40fa39d9bce7 modernized method setup;
wenzelm
parents: 30609
diff changeset
   393
    "simplification (all goals)";
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   394
26497
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   395
fun easy_setup reflect trivs = method_setup [] #> Context.theory_map (map_ss (fn _ =>
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   396
  let
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   397
    val trivialities = Drule.reflexive_thm :: trivs;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   398
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   399
    fun unsafe_solver_tac prems = FIRST' [resolve_tac (trivialities @ prems), assume_tac];
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   400
    val unsafe_solver = mk_solver "easy unsafe" unsafe_solver_tac;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   401
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   402
    (*no premature instantiation of variables during simplification*)
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   403
    fun safe_solver_tac prems = FIRST' [match_tac (trivialities @ prems), eq_assume_tac];
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   404
    val safe_solver = mk_solver "easy safe" safe_solver_tac;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   405
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   406
    fun mk_eq thm =
20872
wenzelm
parents: 18988
diff changeset
   407
      if can Logic.dest_equals (Thm.concl_of thm) then [thm]
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   408
      else [thm RS reflect] handle THM _ => [];
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   409
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26497
diff changeset
   410
    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: 26463
diff changeset
   411
  in
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   412
    empty_ss setsubgoaler asm_simp_tac
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   413
    setSSolver safe_solver
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   414
    setSolver unsafe_solver
36543
0e7fc5bf38de proper context for mksimps etc. -- via simpset of the running Simplifier;
wenzelm
parents: 35613
diff changeset
   415
    setmksimps (K mksimps)
26497
1873915c64a9 purely functional setup of claset/simpset/clasimpset;
wenzelm
parents: 26463
diff changeset
   416
  end));
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   417
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   418
end;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   419
32738
15bb09ca0378 explicit indication of Unsynchronized.ref;
wenzelm
parents: 32148
diff changeset
   420
structure Basic_Simplifier: BASIC_SIMPLIFIER = Simplifier;
15bb09ca0378 explicit indication of Unsynchronized.ref;
wenzelm
parents: 32148
diff changeset
   421
open Basic_Simplifier;