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