src/Pure/simplifier.ML
author wenzelm
Wed, 28 Feb 2007 22:05:44 +0100
changeset 22379 abfcb9899d41
parent 22236 1502e0138d5b
child 22709 9ab51bac6287
permissions -rw-r--r--
exported get_ss, map_ss;
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
    ID:         $Id$
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     3
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     4
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     5
Generic simplifier, suitable for most logics (see also
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     6
meta_simplifier.ML for the actual meta-level rewriting engine).
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     7
*)
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     8
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
     9
signature BASIC_SIMPLIFIER =
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    10
sig
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    11
  include BASIC_META_SIMPLIFIER
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    12
  val print_simpset: theory -> unit
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
    13
  val change_simpset_of: theory -> (simpset -> simpset) -> unit
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
    14
  val change_simpset: (simpset -> simpset) -> unit
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    15
  val simpset_of: theory -> simpset
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
    16
  val simpset: unit -> simpset
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    17
  val SIMPSET: (simpset -> tactic) -> tactic
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    18
  val SIMPSET': (simpset -> 'a -> tactic) -> 'a -> tactic
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    19
  val Addsimps: thm list -> unit
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    20
  val Delsimps: thm list -> unit
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    21
  val Addsimprocs: simproc list -> unit
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    22
  val Delsimprocs: simproc list -> unit
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    23
  val Addcongs: thm list -> unit
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    24
  val Delcongs: thm list -> unit
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    25
  val local_simpset_of: Proof.context -> simpset
17967
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
    26
  val generic_simp_tac: bool -> bool * bool * bool -> simpset -> int -> tactic
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    27
  val safe_asm_full_simp_tac: simpset -> int -> tactic
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    28
  val               simp_tac: simpset -> int -> tactic
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    29
  val           asm_simp_tac: simpset -> int -> tactic
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    30
  val          full_simp_tac: simpset -> int -> tactic
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    31
  val        asm_lr_simp_tac: simpset -> int -> tactic
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    32
  val      asm_full_simp_tac: simpset -> int -> tactic
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    33
  val               Simp_tac:            int -> tactic
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    34
  val           Asm_simp_tac:            int -> tactic
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    35
  val          Full_simp_tac:            int -> tactic
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    36
  val        Asm_lr_simp_tac:            int -> tactic
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    37
  val      Asm_full_simp_tac:            int -> tactic
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    38
  val          simplify: simpset -> thm -> thm
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    39
  val      asm_simplify: simpset -> thm -> thm
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    40
  val     full_simplify: simpset -> thm -> thm
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    41
  val   asm_lr_simplify: simpset -> thm -> thm
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    42
  val asm_full_simplify: simpset -> thm -> thm
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    43
end;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    44
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    45
signature SIMPLIFIER =
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    46
sig
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    47
  include BASIC_SIMPLIFIER
17004
6a0d8ecf65f1 export clear_ss;
wenzelm
parents: 16989
diff changeset
    48
  val clear_ss: simpset -> simpset
17723
ee5b42e3cbb4 export debug_bounds;
wenzelm
parents: 17004
diff changeset
    49
  val debug_bounds: bool ref
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
    50
  val inherit_context: simpset -> simpset -> simpset
17898
ff78ecd1e768 renamed set_context to context;
wenzelm
parents: 17883
diff changeset
    51
  val the_context: simpset -> Proof.context
ff78ecd1e768 renamed set_context to context;
wenzelm
parents: 17883
diff changeset
    52
  val context: Proof.context -> simpset -> simpset
ff78ecd1e768 renamed set_context to context;
wenzelm
parents: 17883
diff changeset
    53
  val theory_context: theory  -> simpset -> simpset
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16014
diff changeset
    54
  val simproc_i: theory -> string -> term list
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16014
diff changeset
    55
    -> (theory -> simpset -> term -> thm option) -> simproc
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16014
diff changeset
    56
  val simproc: theory -> string -> string list
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16014
diff changeset
    57
    -> (theory -> simpset -> term -> thm option) -> simproc
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    58
  val          rewrite: simpset -> cterm -> thm
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    59
  val      asm_rewrite: simpset -> cterm -> thm
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    60
  val     full_rewrite: simpset -> cterm -> thm
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    61
  val   asm_lr_rewrite: simpset -> cterm -> thm
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    62
  val asm_full_rewrite: simpset -> cterm -> thm
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
    63
  val get_simpset: theory -> simpset
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    64
  val print_local_simpset: Proof.context -> unit
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    65
  val get_local_simpset: Proof.context -> simpset
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    66
  val put_local_simpset: simpset -> Proof.context -> Proof.context
22379
abfcb9899d41 exported get_ss, map_ss;
wenzelm
parents: 22236
diff changeset
    67
  val get_ss: Context.generic -> simpset
abfcb9899d41 exported get_ss, map_ss;
wenzelm
parents: 22236
diff changeset
    68
  val map_ss: (simpset -> simpset) -> Context.generic -> Context.generic
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    69
  val attrib: (simpset * thm list -> simpset) -> attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    70
  val simp_add: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    71
  val simp_del: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    72
  val cong_add: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    73
  val cong_del: attribute
22204
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
    74
  val get_simproc: Proof.context -> xstring -> simproc
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
    75
  val def_simproc: {name: string, lhss: string list,
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
    76
    proc: morphism -> simpset -> cterm -> thm option, identifier: thm list} ->
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
    77
    local_theory -> local_theory
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
    78
  val def_simproc_i: {name: string, lhss: term list,
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
    79
    proc: morphism -> simpset -> cterm -> thm option, identifier: thm list} ->
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
    80
    local_theory -> local_theory
18033
ab8803126f84 export cong_modifiers, simp_modifiers';
wenzelm
parents: 17967
diff changeset
    81
  val cong_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list
ab8803126f84 export cong_modifiers, simp_modifiers';
wenzelm
parents: 17967
diff changeset
    82
  val simp_modifiers': (Args.T list -> (Method.modifier * Args.T list)) list
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    83
  val simp_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    84
  val method_setup: (Args.T list -> (Method.modifier * Args.T list)) list
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
    85
    -> theory -> theory
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
    86
  val easy_setup: thm -> thm list -> theory -> theory
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    87
end;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    88
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    89
structure Simplifier: SIMPLIFIER =
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    90
struct
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    91
21708
45e7491bea47 reorganized structure Tactic vs. MetaSimplifier;
wenzelm
parents: 21687
diff changeset
    92
open MetaSimplifier;
45e7491bea47 reorganized structure Tactic vs. MetaSimplifier;
wenzelm
parents: 21687
diff changeset
    93
45e7491bea47 reorganized structure Tactic vs. MetaSimplifier;
wenzelm
parents: 21687
diff changeset
    94
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
    95
(** simpset data **)
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    96
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
    97
(* global simpsets *)
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
    98
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16014
diff changeset
    99
structure GlobalSimpset = TheoryDataFun
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16014
diff changeset
   100
(struct
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   101
  val name = "Pure/simpset";
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   102
  type T = simpset ref;
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   103
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   104
  val empty = ref empty_ss;
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   105
  fun copy (ref ss) = ref ss: T;            (*create new reference!*)
17898
ff78ecd1e768 renamed set_context to context;
wenzelm
parents: 17883
diff changeset
   106
  fun extend (ref ss) = ref (MetaSimplifier.inherit_context empty_ss ss);
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   107
  fun merge _ (ref ss1, ref ss2) = ref (merge_ss (ss1, ss2));
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   108
  fun print _ (ref ss) = print_ss ss;
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16014
diff changeset
   109
end);
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   110
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   111
val _ = Context.add_setup GlobalSimpset.init;
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   112
val print_simpset = GlobalSimpset.print;
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   113
val get_simpset = ! o GlobalSimpset.get;
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   114
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   115
val change_simpset_of = change o GlobalSimpset.get;
22095
07875394618e moved ML context stuff to from Context to ML_Context;
wenzelm
parents: 21708
diff changeset
   116
fun change_simpset f = change_simpset_of (ML_Context.the_context ()) f;
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   117
17898
ff78ecd1e768 renamed set_context to context;
wenzelm
parents: 17883
diff changeset
   118
fun simpset_of thy = MetaSimplifier.context (ProofContext.init thy) (get_simpset thy);
22095
07875394618e moved ML context stuff to from Context to ML_Context;
wenzelm
parents: 21708
diff changeset
   119
val simpset = simpset_of o ML_Context.the_context;
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   120
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   121
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   122
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
   123
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
   124
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   125
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
   126
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
   127
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
   128
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
   129
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
   130
fun Delcongs args = change_simpset (fn ss => ss delcongs args);
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   131
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   132
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   133
(* local simpsets *)
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   134
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16014
diff changeset
   135
structure LocalSimpset = ProofDataFun
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16014
diff changeset
   136
(struct
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   137
  val name = "Pure/simpset";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   138
  type T = simpset;
17883
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   139
  val init = get_simpset;
efa1bc2bdcc6 removed obsolete/experimental context components (superceded by Simplifier.the_context);
wenzelm
parents: 17723
diff changeset
   140
  fun print _ ss = print_ss ss;
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16014
diff changeset
   141
end);
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   142
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   143
val _ = Context.add_setup LocalSimpset.init;
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   144
val print_local_simpset = LocalSimpset.print;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   145
val get_local_simpset = LocalSimpset.get;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   146
val put_local_simpset = LocalSimpset.put;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   147
17898
ff78ecd1e768 renamed set_context to context;
wenzelm
parents: 17883
diff changeset
   148
fun local_simpset_of ctxt = MetaSimplifier.context ctxt (get_local_simpset ctxt);
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   149
22132
0f26cd597193 added @{simpset};
wenzelm
parents: 22095
diff changeset
   150
val _ = ML_Context.value_antiq "simpset"
0f26cd597193 added @{simpset};
wenzelm
parents: 22095
diff changeset
   151
  (Scan.succeed ("simpset", "Simplifier.local_simpset_of (ML_Context.the_local_context ())"));
0f26cd597193 added @{simpset};
wenzelm
parents: 22095
diff changeset
   152
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   153
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   154
(* generic simpsets *)
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
fun get_ss (Context.Theory thy) = simpset_of thy
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   157
  | get_ss (Context.Proof ctxt) = local_simpset_of ctxt;
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   158
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   159
fun map_ss f (Context.Theory thy) = (change_simpset_of thy f; Context.Theory thy)
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   160
  | map_ss f (Context.Proof ctxt) = Context.Proof (LocalSimpset.map f ctxt);
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   161
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   162
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   163
(* attributes *)
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   164
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   165
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
   166
18688
abf0f018b5ec generic attributes;
wenzelm
parents: 18629
diff changeset
   167
val simp_add = attrib (op addsimps);
abf0f018b5ec generic attributes;
wenzelm
parents: 18629
diff changeset
   168
val simp_del = attrib (op delsimps);
abf0f018b5ec generic attributes;
wenzelm
parents: 18629
diff changeset
   169
val cong_add = attrib (op addcongs);
abf0f018b5ec generic attributes;
wenzelm
parents: 18629
diff changeset
   170
val cong_del = attrib (op delcongs);
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   171
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   172
17967
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   173
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   174
(** named simprocs **)
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
fun err_dup_simprocs ds =
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   177
  error ("Duplicate simproc(s): " ^ commas_quote ds);
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   178
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   179
22204
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   180
(* data *)
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   181
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   182
structure Simprocs = GenericDataFun
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   183
(
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   184
  val name = "Pure/simprocs";
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   185
  type T = simproc NameSpace.table;
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   186
  val empty = NameSpace.empty_table;
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   187
  val extend = I;
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   188
  fun merge _ simprocs = NameSpace.merge_tables eq_simproc simprocs
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   189
    handle Symtab.DUPS ds => err_dup_simprocs ds;
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   190
  fun print _ _ = ();
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   191
);
22204
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   192
val _ = Context.add_setup Simprocs.init;
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   193
22204
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   194
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   195
(* get simprocs *)
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   196
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   197
fun get_simproc ctxt xname =
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   198
  let
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   199
    val (space, tab) = Simprocs.get (Context.Proof ctxt);
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   200
    val name = NameSpace.intern space xname;
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   201
  in
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   202
    (case Symtab.lookup tab name of
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   203
      SOME proc => proc
22204
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   204
    | NONE => error ("Undefined simplification procedure: " ^ quote name))
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   205
  end;
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   206
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   207
val _ = ML_Context.value_antiq "simproc" (Scan.lift Args.name >> (fn name =>
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   208
  ("simproc",
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   209
    "Simplifier.get_simproc (ML_Context.the_local_context ()) " ^ ML_Syntax.print_string name)));
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   210
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   211
33da3a55c00e added get_simproc, @{simproc};
wenzelm
parents: 22201
diff changeset
   212
(* define simprocs *)
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   213
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   214
local
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   215
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   216
(* FIXME *)
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   217
fun read_terms ctxt ts =
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   218
  #1 (ProofContext.read_termTs ctxt (K false) (K NONE) (K NONE) []
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   219
    (map (rpair TypeInfer.logicT) ts));
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   220
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   221
(* FIXME *)
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   222
fun cert_terms ctxt ts = map (ProofContext.cert_term ctxt) ts;
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   223
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   224
fun gen_simproc prep {name, lhss, proc, identifier} lthy =
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   225
  let
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   226
    val naming = LocalTheory.full_naming lthy;
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   227
    val simproc = make_simproc
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   228
      {name = LocalTheory.full_name lthy name,
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   229
       lhss =
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   230
        let
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   231
          val lhss' = prep lthy lhss;
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   232
          val ctxt' = lthy
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   233
            |> fold Variable.declare_term lhss'
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   234
            |> fold Variable.auto_fixes lhss';
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   235
        in Variable.export_terms ctxt' lthy lhss' end
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   236
        |> map (Thm.cterm_of (ProofContext.theory_of lthy)),
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   237
       proc = proc,
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   238
       identifier = identifier}
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   239
      |> morph_simproc (LocalTheory.target_morphism lthy);
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   240
  in
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   241
    lthy |> LocalTheory.declaration (fn phi => fn context =>
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   242
      let
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   243
        val name' = Morphism.name phi name;
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   244
        val simproc' = morph_simproc phi simproc;
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   245
      in
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   246
        context
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   247
        |> Simprocs.map (fn simprocs =>
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   248
            NameSpace.extend_table naming (simprocs, [(name', simproc')])
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   249
              handle Symtab.DUPS ds => err_dup_simprocs ds)
22236
1502e0138d5b def_simproc(_i): tuned interface;
wenzelm
parents: 22204
diff changeset
   250
        |> map_ss (fn ss => ss addsimprocs [simproc'])
22201
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   251
      end)
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   252
  end;
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   253
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   254
in
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   255
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   256
val def_simproc = gen_simproc read_terms;
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   257
val def_simproc_i = gen_simproc cert_terms;
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   258
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   259
end;
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   260
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   261
6fe46a7259ec added def_simproc(_i) -- define named simprocs;
wenzelm
parents: 22132
diff changeset
   262
17967
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   263
(** simplification tactics and rules **)
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   264
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   265
fun solve_all_tac solvers ss =
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   266
  let
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   267
    val (_, {subgoal_tac, ...}) = MetaSimplifier.rep_ss ss;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   268
    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
   269
  in DEPTH_SOLVE (solve_tac 1) end;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   270
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   271
(*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
   272
fun generic_simp_tac safe mode ss =
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   273
  let
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   274
    val (_, {loop_tacs, solvers = (unsafe_solvers, solvers), ...}) = MetaSimplifier.rep_ss ss;
21286
b5e7b80caa6a introduces canonical AList functions for loop_tacs
haftmann
parents: 20872
diff changeset
   275
    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
   276
    val solve_tac = FIRST' (map (MetaSimplifier.solver ss)
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   277
      (if safe then solvers else unsafe_solvers));
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   278
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   279
    fun simp_loop_tac i =
21687
f689f729afab reorganized structure Goal vs. Tactic;
wenzelm
parents: 21286
diff changeset
   280
      Goal.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
   281
      (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
   282
  in simp_loop_tac end;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   283
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   284
local
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   285
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   286
fun simp rew mode ss thm =
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   287
  let
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   288
    val (_, {solvers = (unsafe_solvers, _), ...}) = MetaSimplifier.rep_ss ss;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   289
    val tacf = solve_all_tac unsafe_solvers;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   290
    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
   291
  in rew mode prover ss thm end;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   292
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   293
in
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   294
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   295
val simp_thm = simp MetaSimplifier.rewrite_thm;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   296
val simp_cterm = simp MetaSimplifier.rewrite_cterm;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   297
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   298
end;
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   299
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   300
16806
916387f7afd2 removed obsolete delta stuff;
wenzelm
parents: 16709
diff changeset
   301
(* tactics *)
916387f7afd2 removed obsolete delta stuff;
wenzelm
parents: 16709
diff changeset
   302
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   303
val simp_tac = generic_simp_tac false (false, false, false);
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   304
val asm_simp_tac = generic_simp_tac false (false, true, false);
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   305
val full_simp_tac = generic_simp_tac false (true, false, false);
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   306
val asm_lr_simp_tac = generic_simp_tac false (true, true, false);
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   307
val asm_full_simp_tac = generic_simp_tac false (true, true, true);
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   308
val safe_asm_full_simp_tac = generic_simp_tac true (true, true, true);
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   309
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   310
(*the abstraction over the proof state delays the dereferencing*)
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   311
fun          Simp_tac i st =          simp_tac (simpset ()) i st;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   312
fun      Asm_simp_tac i st =      asm_simp_tac (simpset ()) i st;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   313
fun     Full_simp_tac i st =     full_simp_tac (simpset ()) i st;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   314
fun   Asm_lr_simp_tac i st =   asm_lr_simp_tac (simpset ()) i st;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   315
fun Asm_full_simp_tac i st = asm_full_simp_tac (simpset ()) i st;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   316
16806
916387f7afd2 removed obsolete delta stuff;
wenzelm
parents: 16709
diff changeset
   317
916387f7afd2 removed obsolete delta stuff;
wenzelm
parents: 16709
diff changeset
   318
(* conversions *)
916387f7afd2 removed obsolete delta stuff;
wenzelm
parents: 16709
diff changeset
   319
17967
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   320
val          simplify = simp_thm (false, false, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   321
val      asm_simplify = simp_thm (false, true, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   322
val     full_simplify = simp_thm (true, false, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   323
val   asm_lr_simplify = simp_thm (true, true, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   324
val asm_full_simplify = simp_thm (true, true, true);
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   325
17967
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   326
val          rewrite = simp_cterm (false, false, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   327
val      asm_rewrite = simp_cterm (false, true, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   328
val     full_rewrite = simp_cterm (true, false, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   329
val   asm_lr_rewrite = simp_cterm (true, true, false);
7a733b7438e1 added simplification tactics and rules (from meta_simplifier.ML);
wenzelm
parents: 17898
diff changeset
   330
val asm_full_rewrite = simp_cterm (true, true, true);
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   331
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   332
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   333
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   334
(** concrete syntax of attributes **)
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   335
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   336
(* add / del *)
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   337
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   338
val simpN = "simp";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   339
val congN = "cong";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   340
val addN = "add";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   341
val delN = "del";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   342
val onlyN = "only";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   343
val no_asmN = "no_asm";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   344
val no_asm_useN = "no_asm_use";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   345
val no_asm_simpN = "no_asm_simp";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   346
val asm_lrN = "asm_lr";
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   347
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   348
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   349
(* conversions *)
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   350
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   351
local
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   352
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   353
fun conv_mode x =
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   354
  ((Args.parens (Args.$$$ no_asmN) >> K simplify ||
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   355
    Args.parens (Args.$$$ no_asm_simpN) >> K asm_simplify ||
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   356
    Args.parens (Args.$$$ no_asm_useN) >> K full_simplify ||
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   357
    Scan.succeed asm_full_simplify) |> Scan.lift) x;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   358
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   359
in
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   360
18688
abf0f018b5ec generic attributes;
wenzelm
parents: 18629
diff changeset
   361
val simplified =
18988
d6e5fa2ba8b8 Args/Attrib syntax: Context.generic;
wenzelm
parents: 18728
diff changeset
   362
  Attrib.syntax (conv_mode -- Attrib.thms >> (fn (f, ths) => Thm.rule_attribute (fn x =>
18688
abf0f018b5ec generic attributes;
wenzelm
parents: 18629
diff changeset
   363
    f ((if null ths then I else MetaSimplifier.clear_ss) (get_ss x) addsimps ths))));
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   364
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   365
end;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   366
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   367
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   368
(* setup attributes *)
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   369
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   370
val _ = Context.add_setup
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   371
 (Attrib.add_attributes
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   372
   [(simpN, Attrib.add_del_args simp_add simp_del, "declaration of Simplifier rule"),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   373
    (congN, Attrib.add_del_args cong_add cong_del, "declaration of Simplifier congruence rule"),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
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
16685
4ffc943c9c75 made smlnj happy;
wenzelm
parents: 16684
diff changeset
   389
fun simp_flags x = (Scan.repeat
16684
7b58002668c0 methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents: 16458
diff changeset
   390
  (Args.parens (Args.$$$ "depth_limit" -- Args.colon |-- Args.nat)
7b58002668c0 methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents: 16458
diff changeset
   391
    >> setmp MetaSimplifier.simp_depth_limit)
16709
a4679ac06502 multiple flags: prefer later ones;
wenzelm
parents: 16685
diff changeset
   392
  >> (curry (Library.foldl op o) I o rev)) x;
16684
7b58002668c0 methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents: 16458
diff changeset
   393
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   394
val cong_modifiers =
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   395
 [Args.$$$ congN -- Args.colon >> K ((I, cong_add): Method.modifier),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   396
  Args.$$$ congN -- Args.add -- Args.colon >> K (I, cong_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   397
  Args.$$$ congN -- Args.del -- Args.colon >> K (I, cong_del)];
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   398
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   399
val simp_modifiers =
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   400
 [Args.$$$ simpN -- Args.colon >> K (I, simp_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   401
  Args.$$$ simpN -- Args.add -- Args.colon >> K (I, simp_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   402
  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
   403
  Args.$$$ simpN -- Args.$$$ onlyN -- Args.colon
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   404
    >> K (LocalSimpset.map MetaSimplifier.clear_ss, simp_add)]
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   405
   @ cong_modifiers;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   406
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   407
val simp_modifiers' =
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   408
 [Args.add -- Args.colon >> K (I, simp_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   409
  Args.del -- Args.colon >> K (I, simp_del),
18688
abf0f018b5ec generic attributes;
wenzelm
parents: 18629
diff changeset
   410
  Args.$$$ onlyN -- Args.colon
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   411
    >> K (LocalSimpset.map MetaSimplifier.clear_ss, simp_add)]
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   412
   @ cong_modifiers;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   413
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   414
fun simp_args more_mods =
16684
7b58002668c0 methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents: 16458
diff changeset
   415
  Method.sectioned_args (Args.bang_facts -- Scan.lift simp_options -- Scan.lift simp_flags)
7b58002668c0 methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents: 16458
diff changeset
   416
    (more_mods @ simp_modifiers');
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   417
16684
7b58002668c0 methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents: 16458
diff changeset
   418
fun simp_method ((prems, tac), FLAGS) ctxt = Method.METHOD (fn facts =>
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   419
  ALLGOALS (Method.insert_tac (prems @ facts)) THEN
16684
7b58002668c0 methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents: 16458
diff changeset
   420
    (FLAGS o CHANGED_PROP o ALLGOALS o tac) (local_simpset_of ctxt));
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   421
16684
7b58002668c0 methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents: 16458
diff changeset
   422
fun simp_method' ((prems, tac), FLAGS) ctxt = Method.METHOD (fn facts =>
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   423
  HEADGOAL (Method.insert_tac (prems @ facts) THEN'
16684
7b58002668c0 methods: added simp_flags argument, added "depth_limit" flag;
wenzelm
parents: 16458
diff changeset
   424
      ((FLAGS o CHANGED_PROP) oo tac) (local_simpset_of ctxt)));
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   425
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   426
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   427
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   428
(** setup **)
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   429
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   430
fun method_setup more_mods = Method.add_methods
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   431
 [(simpN, simp_args more_mods simp_method', "simplification"),
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   432
  ("simp_all", simp_args more_mods simp_method, "simplification (all goals)")];
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   433
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   434
fun easy_setup reflect trivs = method_setup [] #> (fn thy =>
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   435
  let
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   436
    val trivialities = Drule.reflexive_thm :: trivs;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   437
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   438
    fun unsafe_solver_tac prems = FIRST' [resolve_tac (trivialities @ prems), assume_tac];
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   439
    val unsafe_solver = mk_solver "easy unsafe" unsafe_solver_tac;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   440
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   441
    (*no premature instantiation of variables during simplification*)
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   442
    fun safe_solver_tac prems = FIRST' [match_tac (trivialities @ prems), eq_assume_tac];
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   443
    val safe_solver = mk_solver "easy safe" safe_solver_tac;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   444
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   445
    fun mk_eq thm =
20872
wenzelm
parents: 18988
diff changeset
   446
      if can Logic.dest_equals (Thm.concl_of thm) then [thm]
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   447
      else [thm RS reflect] handle THM _ => [];
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   448
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   449
    fun mksimps thm = mk_eq (Drule.forall_elim_vars (#maxidx (Thm.rep_thm thm) + 1) thm);
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   450
  in
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   451
    GlobalSimpset.get thy :=
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   452
      empty_ss setsubgoaler asm_simp_tac
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   453
      setSSolver safe_solver
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   454
      setSolver unsafe_solver
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   455
      setmksimps mksimps;
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   456
    thy
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   457
  end);
16014
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   458
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   459
end;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   460
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   461
structure BasicSimplifier: BASIC_SIMPLIFIER = Simplifier;
85f4b0f81f62 moved here from Provers;
wenzelm
parents:
diff changeset
   462
open BasicSimplifier;