src/Provers/simplifier.ML
author wenzelm
Thu, 07 Sep 2000 20:56:04 +0200
changeset 9899 5a9081c3b869
parent 9861 b2a6d854d6da
child 9952 24914e42b857
permissions -rw-r--r--
tuned att names / msgs;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1243
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
     1
(*  Title:      Provers/simplifier.ML
1
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
     2
    ID:         $Id$
3557
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
     3
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
1
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
     4
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
     5
Generic simplifier, suitable for most logics.  See Pure/thm.ML for the
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
     6
actual meta-level rewriting engine.
1
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
     7
*)
1260
c76ac4a9dc2b renamed SS to Simpset; fixed bug in merge_ss
clasohm
parents: 1243
diff changeset
     8
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
     9
infix 4
4682
ff081854fc86 Added delspilts, Addsplits, Delsplits.
nipkow
parents: 4677
diff changeset
    10
  setsubgoaler setloop addloop delloop setSSolver addSSolver setSolver
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
    11
  addSolver addsimps delsimps addeqcongs deleqcongs addcongs delcongs
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
    12
  setmksimps setmkeqTrue setmkcong setmksym settermless addsimprocs delsimprocs;
2567
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
    13
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
    14
signature BASIC_SIMPLIFIER =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
sig
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    16
  type simproc
3577
9715b6e3ec5f added prems argument to simplification procedures;
wenzelm
parents: 3557
diff changeset
    17
  val mk_simproc: string -> cterm list
9715b6e3ec5f added prems argument to simplification procedures;
wenzelm
parents: 3557
diff changeset
    18
    -> (Sign.sg -> thm list -> term -> thm option) -> simproc
7568
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
    19
  type solver
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
    20
  val mk_solver: string -> (thm list -> int -> tactic) -> solver
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
  type simpset
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    22
  val empty_ss: simpset
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
    23
  val rep_ss: simpset ->
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
    24
   {mss: meta_simpset,
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
    25
    mk_cong: thm -> thm,
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
    26
    subgoal_tac: simpset -> int -> tactic,
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
    27
    loop_tacs: (string * (int -> tactic)) list,
7568
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
    28
    unsafe_solvers: solver list,
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
    29
    solvers: solver list};
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
    30
  val print_ss: simpset -> unit
4366
4d84cdb0df42 added print_simpset;
wenzelm
parents: 4290
diff changeset
    31
  val print_simpset: theory -> unit
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    32
  val setsubgoaler: simpset *  (simpset -> int -> tactic) -> simpset
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    33
  val setloop:      simpset *             (int -> tactic) -> simpset
4668
131989b78417 Little reorganization. Loop tactics have names now.
nipkow
parents: 4612
diff changeset
    34
  val addloop:      simpset *  (string * (int -> tactic)) -> simpset
4682
ff081854fc86 Added delspilts, Addsplits, Delsplits.
nipkow
parents: 4677
diff changeset
    35
  val delloop:      simpset *   string                    -> simpset
7568
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
    36
  val setSSolver:   simpset * solver -> simpset
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
    37
  val addSSolver:   simpset * solver -> simpset
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
    38
  val setSolver:    simpset * solver -> simpset
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
    39
  val addSolver:    simpset * solver -> simpset
3577
9715b6e3ec5f added prems argument to simplification procedures;
wenzelm
parents: 3557
diff changeset
    40
  val setmksimps:   simpset * (thm -> thm list) -> simpset
4677
c4b07b8579fd Reorganized simplifier. May now reorient rules.
nipkow
parents: 4668
diff changeset
    41
  val setmkeqTrue:  simpset * (thm -> thm option) -> simpset
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
    42
  val setmkcong:    simpset * (thm -> thm) -> simpset
4677
c4b07b8579fd Reorganized simplifier. May now reorient rules.
nipkow
parents: 4668
diff changeset
    43
  val setmksym:     simpset * (thm -> thm option) -> simpset
3577
9715b6e3ec5f added prems argument to simplification procedures;
wenzelm
parents: 3557
diff changeset
    44
  val settermless:  simpset * (term * term -> bool) -> simpset
9715b6e3ec5f added prems argument to simplification procedures;
wenzelm
parents: 3557
diff changeset
    45
  val addsimps:     simpset * thm list -> simpset
9715b6e3ec5f added prems argument to simplification procedures;
wenzelm
parents: 3557
diff changeset
    46
  val delsimps:     simpset * thm list -> simpset
9715b6e3ec5f added prems argument to simplification procedures;
wenzelm
parents: 3557
diff changeset
    47
  val addeqcongs:   simpset * thm list -> simpset
9715b6e3ec5f added prems argument to simplification procedures;
wenzelm
parents: 3557
diff changeset
    48
  val deleqcongs:   simpset * thm list -> simpset
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
    49
  val addcongs:     simpset * thm list -> simpset
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
    50
  val delcongs:     simpset * thm list -> simpset
3577
9715b6e3ec5f added prems argument to simplification procedures;
wenzelm
parents: 3557
diff changeset
    51
  val addsimprocs:  simpset * simproc list -> simpset
9715b6e3ec5f added prems argument to simplification procedures;
wenzelm
parents: 3557
diff changeset
    52
  val delsimprocs:  simpset * simproc list -> simpset
9715b6e3ec5f added prems argument to simplification procedures;
wenzelm
parents: 3557
diff changeset
    53
  val merge_ss:     simpset * simpset -> simpset
9715b6e3ec5f added prems argument to simplification procedures;
wenzelm
parents: 3557
diff changeset
    54
  val prems_of_ss:  simpset -> thm list
4080
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
    55
  val simpset_ref_of_sg: Sign.sg -> simpset ref
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
    56
  val simpset_ref_of: theory -> simpset ref
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
    57
  val simpset_of_sg: Sign.sg -> simpset
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
    58
  val simpset_of: theory -> simpset
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
    59
  val SIMPSET: (simpset -> tactic) -> tactic
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
    60
  val SIMPSET': (simpset -> 'a -> tactic) -> 'a -> tactic
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
    61
  val simpset: unit -> simpset
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
    62
  val simpset_ref: unit -> simpset ref
1243
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
    63
  val Addsimps: thm list -> unit
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
    64
  val Delsimps: thm list -> unit
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    65
  val Addsimprocs: simproc list -> unit
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    66
  val Delsimprocs: simproc list -> unit
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
    67
  val Addcongs: thm list -> unit
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
    68
  val Delcongs: thm list -> unit
8879
bf487b29a9a6 export generic_simp_tac;
wenzelm
parents: 8815
diff changeset
    69
  val generic_simp_tac: bool -> bool * bool * bool -> simpset -> int -> tactic
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    70
  val               simp_tac: simpset -> int -> tactic
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    71
  val           asm_simp_tac: simpset -> int -> tactic
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    72
  val          full_simp_tac: simpset -> int -> tactic
4722
d2e44673c21e The new asm_lr_simp_tac is the old asm_full_simp_tac.
nipkow
parents: 4713
diff changeset
    73
  val        asm_lr_simp_tac: simpset -> int -> tactic
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    74
  val      asm_full_simp_tac: simpset -> int -> tactic
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    75
  val               Simp_tac:            int -> tactic
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    76
  val           Asm_simp_tac:            int -> tactic
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    77
  val          Full_simp_tac:            int -> tactic
4722
d2e44673c21e The new asm_lr_simp_tac is the old asm_full_simp_tac.
nipkow
parents: 4713
diff changeset
    78
  val        Asm_lr_simp_tac:            int -> tactic
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    79
  val      Asm_full_simp_tac:            int -> tactic
3557
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
    80
  val          simplify: simpset -> thm -> thm
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
    81
  val      asm_simplify: simpset -> thm -> thm
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
    82
  val     full_simplify: simpset -> thm -> thm
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
    83
  val asm_full_simplify: simpset -> thm -> thm
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    84
end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    85
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
    86
signature SIMPLIFIER =
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
    87
sig
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
    88
  include BASIC_SIMPLIFIER
5082
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
    89
  val          rewrite: simpset -> cterm -> thm
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
    90
  val      asm_rewrite: simpset -> cterm -> thm
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
    91
  val     full_rewrite: simpset -> cterm -> thm
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
    92
  val asm_full_rewrite: simpset -> cterm -> thm
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
    93
  val print_local_simpset: Proof.context -> unit
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
    94
  val get_local_simpset: Proof.context -> simpset
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
    95
  val put_local_simpset: simpset -> Proof.context -> Proof.context
8467
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
    96
  val change_global_ss: (simpset * thm list -> simpset) -> theory attribute
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
    97
  val change_local_ss: (simpset * thm list -> simpset) -> Proof.context attribute
4855
62bc389d6168 tuned setup;
wenzelm
parents: 4795
diff changeset
    98
  val simp_add_global: theory attribute
62bc389d6168 tuned setup;
wenzelm
parents: 4795
diff changeset
    99
  val simp_del_global: theory attribute
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   100
  val simp_add_local: Proof.context attribute
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   101
  val simp_del_local: Proof.context attribute
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   102
  val cong_add_global: theory attribute
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   103
  val cong_del_global: theory attribute
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   104
  val cong_add_local: Proof.context attribute
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   105
  val cong_del_local: Proof.context attribute
7177
6bb7ad30f3da change_simpset_of;
wenzelm
parents: 7132
diff changeset
   106
  val change_simpset_of: (simpset * 'a -> simpset) -> 'a -> theory -> theory
7273
d80b9be87535 Method.modifier;
wenzelm
parents: 7217
diff changeset
   107
  val simp_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   108
  val setup: (theory -> theory) list
8467
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
   109
  val method_setup: (Args.T list -> (Method.modifier * Args.T list)) list
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
   110
    -> (theory -> theory) list
8228
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   111
  val easy_setup: thm -> thm list -> (theory -> theory) list
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   112
end;
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   113
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   114
structure Simplifier: SIMPLIFIER =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   115
struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   116
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   117
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   118
(** simplification procedures **)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   119
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   120
(* datatype simproc *)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   121
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   122
datatype simproc =
3577
9715b6e3ec5f added prems argument to simplification procedures;
wenzelm
parents: 3557
diff changeset
   123
  Simproc of string * cterm list * (Sign.sg -> thm list -> term -> thm option) * stamp;
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   124
3557
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   125
fun mk_simproc name lhss proc =
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   126
  Simproc (name, map (Thm.cterm_fun Logic.varify) lhss, proc, stamp ());
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   127
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   128
fun rep_simproc (Simproc args) = args;
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   129
8467
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
   130
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
   131
7568
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   132
(** solvers **)
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   133
7568
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   134
datatype solver = Solver of string * (thm list -> int -> tactic) * stamp;
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   135
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   136
fun mk_solver name solver = Solver(name, solver, stamp());
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   137
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   138
fun eq_solver (Solver(_,_,s1),Solver(_,_,s2)) = s1=s2;
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   139
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   140
val merge_solvers = generic_merge eq_solver I I;
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   141
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   142
fun app_sols [] _ _ = no_tac
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   143
  | app_sols (Solver(_,solver,_)::sols) thms i =
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   144
       solver thms i ORELSE app_sols sols thms i;
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   145
8467
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
   146
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
   147
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   148
(** simplification sets **)
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   149
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   150
(* type simpset *)
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   151
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   152
datatype simpset =
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   153
  Simpset of {
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   154
    mss: meta_simpset,
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   155
    mk_cong: thm -> thm,
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   156
    subgoal_tac: simpset -> int -> tactic,
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   157
    loop_tacs: (string * (int -> tactic)) list,
7568
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   158
    unsafe_solvers: solver list,
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   159
    solvers: solver list};
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   160
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   161
fun make_ss mss mk_cong subgoal_tac loop_tacs unsafe_solvers solvers =
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   162
  Simpset {mss = mss, mk_cong = mk_cong, subgoal_tac = subgoal_tac,
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   163
    loop_tacs = loop_tacs, unsafe_solvers = unsafe_solvers, solvers = solvers};
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   164
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   165
val empty_ss =
6911
ef0f25d0bc2d simp only: attribute, method arg;
wenzelm
parents: 6556
diff changeset
   166
  let val mss = Thm.set_mk_sym (Thm.empty_mss, Some o symmetric_fun)
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   167
  in make_ss mss I (K (K no_tac)) [] [] [] end;
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   168
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   169
fun rep_ss (Simpset args) = args;
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   170
fun prems_of_ss (Simpset {mss, ...}) = Thm.prems_of_mss mss;
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   171
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   172
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   173
(* print simpsets *)
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   174
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   175
fun print_ss ss =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   176
  let
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   177
    val Simpset {mss, ...} = ss;
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   178
    val {simps, procs, congs} = Thm.dest_mss mss;
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   179
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   180
    val pretty_thms = map Display.pretty_thm;
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   181
    fun pretty_proc (name, lhss) =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   182
      Pretty.big_list (name ^ ":") (map Display.pretty_cterm lhss);
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   183
  in
8727
71acc2d8991a Pretty.chunks;
wenzelm
parents: 8700
diff changeset
   184
    [Pretty.big_list "simplification rules:" (pretty_thms simps),
71acc2d8991a Pretty.chunks;
wenzelm
parents: 8700
diff changeset
   185
      Pretty.big_list "simplification procedures:" (map pretty_proc procs),
71acc2d8991a Pretty.chunks;
wenzelm
parents: 8700
diff changeset
   186
      Pretty.big_list "congruences:" (pretty_thms congs)]
71acc2d8991a Pretty.chunks;
wenzelm
parents: 8700
diff changeset
   187
    |> Pretty.chunks |> Pretty.writeln
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   188
  end;
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   189
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   190
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   191
(* extend simpsets *)
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   192
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   193
fun (Simpset {mss, mk_cong, subgoal_tac = _, loop_tacs, unsafe_solvers, solvers})
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   194
    setsubgoaler subgoal_tac =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   195
  make_ss mss mk_cong subgoal_tac loop_tacs unsafe_solvers solvers;
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   196
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   197
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs = _, unsafe_solvers, solvers})
4668
131989b78417 Little reorganization. Loop tactics have names now.
nipkow
parents: 4612
diff changeset
   198
    setloop tac =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   199
  make_ss mss mk_cong subgoal_tac [("", tac)] unsafe_solvers solvers;
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   200
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   201
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, solvers})
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   202
    addloop tac = make_ss mss mk_cong subgoal_tac
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   203
      (case assoc_string (loop_tacs, (#1 tac)) of None => () | Some x =>
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   204
        warning ("overwriting looper " ^ quote (#1 tac)); overwrite (loop_tacs, tac))
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   205
      unsafe_solvers solvers;
2567
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
   206
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   207
fun (ss as Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, solvers})
7214
381d6987f68d exchanged finish_tac and unsafe_finish_tac (the more important one) in simpset
oheimb
parents: 7177
diff changeset
   208
 delloop name =
6911
ef0f25d0bc2d simp only: attribute, method arg;
wenzelm
parents: 6556
diff changeset
   209
  let val (del, rest) = partition (fn (n, _) => n = name) loop_tacs in
ef0f25d0bc2d simp only: attribute, method arg;
wenzelm
parents: 6556
diff changeset
   210
    if null del then (warning ("No such looper in simpset: " ^ name); ss)
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   211
    else make_ss mss mk_cong subgoal_tac rest unsafe_solvers solvers
4682
ff081854fc86 Added delspilts, Addsplits, Delsplits.
nipkow
parents: 4677
diff changeset
   212
  end;
ff081854fc86 Added delspilts, Addsplits, Delsplits.
nipkow
parents: 4677
diff changeset
   213
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   214
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, ...})
7568
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   215
    setSSolver solver =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   216
  make_ss mss mk_cong subgoal_tac loop_tacs unsafe_solvers [solver];
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   217
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   218
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, solvers})
7568
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   219
    addSSolver sol =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   220
  make_ss mss mk_cong subgoal_tac loop_tacs unsafe_solvers (merge_solvers solvers [sol]);
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   221
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   222
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers = _, solvers})
7568
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   223
    setSolver unsafe_solver =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   224
  make_ss mss mk_cong subgoal_tac loop_tacs [unsafe_solver] solvers;
7568
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   225
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   226
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, solvers})
7568
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   227
    addSolver sol =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   228
  make_ss mss mk_cong subgoal_tac loop_tacs (merge_solvers unsafe_solvers [sol]) solvers;
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   229
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   230
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, solvers})
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   231
    setmksimps mk_simps =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   232
  make_ss (Thm.set_mk_rews (mss, mk_simps)) mk_cong subgoal_tac loop_tacs unsafe_solvers solvers;
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   233
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   234
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, solvers})
4677
c4b07b8579fd Reorganized simplifier. May now reorient rules.
nipkow
parents: 4668
diff changeset
   235
    setmkeqTrue mk_eq_True =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   236
  make_ss (Thm.set_mk_eq_True (mss, mk_eq_True)) mk_cong subgoal_tac loop_tacs
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   237
    unsafe_solvers solvers;
4677
c4b07b8579fd Reorganized simplifier. May now reorient rules.
nipkow
parents: 4668
diff changeset
   238
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   239
fun (Simpset {mss, mk_cong = _, subgoal_tac, loop_tacs, unsafe_solvers, solvers})
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   240
    setmkcong mk_cong =
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   241
  make_ss mss mk_cong subgoal_tac loop_tacs unsafe_solvers solvers;
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   242
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   243
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, solvers})
4677
c4b07b8579fd Reorganized simplifier. May now reorient rules.
nipkow
parents: 4668
diff changeset
   244
    setmksym mksym =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   245
  make_ss (Thm.set_mk_sym (mss, mksym)) mk_cong subgoal_tac loop_tacs unsafe_solvers solvers;
4677
c4b07b8579fd Reorganized simplifier. May now reorient rules.
nipkow
parents: 4668
diff changeset
   246
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   247
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs,  unsafe_solvers, solvers})
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   248
    settermless termless =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   249
  make_ss (Thm.set_termless (mss, termless)) mk_cong subgoal_tac loop_tacs
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   250
    unsafe_solvers solvers;
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   251
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   252
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, solvers})
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   253
    addsimps rews =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   254
  make_ss (Thm.add_simps (mss, rews)) mk_cong subgoal_tac loop_tacs unsafe_solvers solvers;
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   255
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   256
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, solvers})
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   257
    delsimps rews =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   258
  make_ss (Thm.del_simps (mss, rews)) mk_cong subgoal_tac loop_tacs unsafe_solvers solvers;
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   259
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   260
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, solvers})
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   261
    addeqcongs newcongs =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   262
  make_ss (Thm.add_congs (mss, newcongs)) mk_cong subgoal_tac loop_tacs unsafe_solvers solvers;
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   263
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   264
fun (Simpset {mss, subgoal_tac, mk_cong, loop_tacs, unsafe_solvers, solvers})
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   265
    deleqcongs oldcongs =
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   266
  make_ss (Thm.del_congs (mss, oldcongs)) mk_cong subgoal_tac loop_tacs unsafe_solvers solvers;
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   267
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   268
fun (ss as Simpset {mk_cong, ...}) addcongs newcongs =
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   269
  ss addeqcongs map mk_cong newcongs;
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   270
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   271
fun (ss as Simpset {mk_cong, ...}) delcongs oldcongs =
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   272
  ss deleqcongs map mk_cong oldcongs;
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   273
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   274
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, solvers})
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   275
    addsimprocs simprocs =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   276
  make_ss (Thm.add_simprocs (mss, map rep_simproc simprocs)) mk_cong subgoal_tac loop_tacs
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   277
    unsafe_solvers solvers;
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   278
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   279
fun (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, solvers})
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   280
    delsimprocs simprocs =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   281
  make_ss (Thm.del_simprocs (mss, map rep_simproc simprocs)) mk_cong subgoal_tac
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   282
    loop_tacs unsafe_solvers solvers;
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   283
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   284
fun clear_ss (Simpset {mss, mk_cong, subgoal_tac, loop_tacs = _, unsafe_solvers, solvers}) =
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   285
  make_ss (Thm.clear_mss mss) mk_cong subgoal_tac [] unsafe_solvers solvers;
6911
ef0f25d0bc2d simp only: attribute, method arg;
wenzelm
parents: 6556
diff changeset
   286
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   287
7568
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   288
(* merge simpsets *)
8467
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
   289
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
   290
(*ignores subgoal_tac of 2nd simpset!*)
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   291
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   292
fun merge_ss
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   293
   (Simpset {mss = mss1, mk_cong, loop_tacs = loop_tacs1, subgoal_tac,
7568
436c87ac2fac Solvers are now named and stamped.
nipkow
parents: 7558
diff changeset
   294
             unsafe_solvers = unsafe_solvers1, solvers = solvers1},
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   295
    Simpset {mss = mss2, mk_cong = _, loop_tacs = loop_tacs2, subgoal_tac = _,
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   296
             unsafe_solvers = unsafe_solvers2, solvers = solvers2}) =
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   297
  make_ss (Thm.merge_mss (mss1, mss2)) mk_cong subgoal_tac
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   298
    (merge_alists loop_tacs1 loop_tacs2)
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   299
    (merge_solvers unsafe_solvers1 unsafe_solvers2)
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   300
    (merge_solvers solvers1 solvers2);
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   301
3557
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   302
8467
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
   303
5024
d42ce3452dea adapted to TheoryDataFun interface;
wenzelm
parents: 5001
diff changeset
   304
(** global and local simpset data **)
4080
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   305
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   306
(* theory data kind 'Provers/simpset' *)
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   307
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   308
structure GlobalSimpsetArgs =
5024
d42ce3452dea adapted to TheoryDataFun interface;
wenzelm
parents: 5001
diff changeset
   309
struct
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   310
  val name = "Provers/simpset";
5024
d42ce3452dea adapted to TheoryDataFun interface;
wenzelm
parents: 5001
diff changeset
   311
  type T = simpset ref;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   312
5024
d42ce3452dea adapted to TheoryDataFun interface;
wenzelm
parents: 5001
diff changeset
   313
  val empty = ref empty_ss;
6556
daa00919502b theory data: copy;
wenzelm
parents: 6534
diff changeset
   314
  fun copy (ref ss) = (ref ss): T;            (*create new reference!*)
daa00919502b theory data: copy;
wenzelm
parents: 6534
diff changeset
   315
  val prep_ext = copy;
5024
d42ce3452dea adapted to TheoryDataFun interface;
wenzelm
parents: 5001
diff changeset
   316
  fun merge (ref ss1, ref ss2) = ref (merge_ss (ss1, ss2));
d42ce3452dea adapted to TheoryDataFun interface;
wenzelm
parents: 5001
diff changeset
   317
  fun print _ (ref ss) = print_ss ss;
d42ce3452dea adapted to TheoryDataFun interface;
wenzelm
parents: 5001
diff changeset
   318
end;
4080
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   319
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   320
structure GlobalSimpset = TheoryDataFun(GlobalSimpsetArgs);
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   321
val print_simpset = GlobalSimpset.print;
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   322
val simpset_ref_of_sg = GlobalSimpset.get_sg;
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   323
val simpset_ref_of = GlobalSimpset.get;
4080
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   324
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   325
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   326
(* access global simpset *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   327
4080
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   328
val simpset_of_sg = ! o simpset_ref_of_sg;
6391
0da748358eff Theory.sign_of;
wenzelm
parents: 6096
diff changeset
   329
val simpset_of = simpset_of_sg o Theory.sign_of;
4080
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   330
6391
0da748358eff Theory.sign_of;
wenzelm
parents: 6096
diff changeset
   331
fun SIMPSET tacf state = tacf (simpset_of_sg (Thm.sign_of_thm state)) state;
0da748358eff Theory.sign_of;
wenzelm
parents: 6096
diff changeset
   332
fun SIMPSET' tacf i state = tacf (simpset_of_sg (Thm.sign_of_thm state)) i state;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   333
5028
61c10aad3d71 Context.the_context;
wenzelm
parents: 5024
diff changeset
   334
val simpset = simpset_of o Context.the_context;
6391
0da748358eff Theory.sign_of;
wenzelm
parents: 6096
diff changeset
   335
val simpset_ref = simpset_ref_of_sg o Theory.sign_of o Context.the_context;
4080
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   336
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   337
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   338
(* change global simpset *)
4080
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   339
7177
6bb7ad30f3da change_simpset_of;
wenzelm
parents: 7132
diff changeset
   340
fun change_simpset_of f x thy =
6bb7ad30f3da change_simpset_of;
wenzelm
parents: 7132
diff changeset
   341
  let val r = simpset_ref_of thy
6bb7ad30f3da change_simpset_of;
wenzelm
parents: 7132
diff changeset
   342
  in r := f (! r, x); thy end;
6bb7ad30f3da change_simpset_of;
wenzelm
parents: 7132
diff changeset
   343
6bb7ad30f3da change_simpset_of;
wenzelm
parents: 7132
diff changeset
   344
fun change_simpset f x = (change_simpset_of f x (Context.the_context ()); ());
4080
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   345
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   346
val Addsimps = change_simpset (op addsimps);
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   347
val Delsimps = change_simpset (op delsimps);
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   348
val Addsimprocs = change_simpset (op addsimprocs);
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   349
val Delsimprocs = change_simpset (op delsimprocs);
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   350
val Addcongs = change_simpset (op addcongs);
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   351
val Delcongs = change_simpset (op delcongs);
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   352
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   353
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   354
(* proof data kind 'Provers/simpset' *)
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   355
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   356
structure LocalSimpsetArgs =
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   357
struct
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   358
  val name = "Provers/simpset";
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   359
  type T = simpset;
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   360
  val init = simpset_of;
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   361
  fun print _ ss = print_ss ss;
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   362
end;
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   363
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   364
structure LocalSimpset = ProofDataFun(LocalSimpsetArgs);
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   365
val print_local_simpset = LocalSimpset.print;
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   366
val get_local_simpset = LocalSimpset.get;
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   367
val put_local_simpset = LocalSimpset.put;
7273
d80b9be87535 Method.modifier;
wenzelm
parents: 7217
diff changeset
   368
fun map_local_simpset f ctxt = put_local_simpset (f (get_local_simpset ctxt)) ctxt;
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   369
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   370
5886
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   371
(* attributes *)
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   372
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   373
fun change_global_ss f (thy, th) =
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   374
  let val r = simpset_ref_of thy
6096
3451f9e88528 eliminated tthm type and Attribute structure;
wenzelm
parents: 5928
diff changeset
   375
  in r := f (! r, [th]); (thy, th) end;
5886
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   376
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   377
fun change_local_ss f (ctxt, th) =
6096
3451f9e88528 eliminated tthm type and Attribute structure;
wenzelm
parents: 5928
diff changeset
   378
  let val ss = f (get_local_simpset ctxt, [th])
5886
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   379
  in (put_local_simpset ss ctxt, th) end;
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   380
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   381
val simp_add_global = change_global_ss (op addsimps);
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   382
val simp_del_global = change_global_ss (op delsimps);
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   383
val simp_add_local = change_local_ss (op addsimps);
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   384
val simp_del_local = change_local_ss (op delsimps);
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   385
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   386
val cong_add_global = change_global_ss (op addcongs);
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   387
val cong_del_global = change_global_ss (op delcongs);
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   388
val cong_add_local = change_local_ss (op addcongs);
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   389
val cong_del_local = change_local_ss (op delcongs);
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   390
5886
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   391
3557
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   392
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   393
(** simplification tactics **)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   394
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   395
fun solve_all_tac (mk_cong, subgoal_tac, loop_tacs, unsafe_solvers) mss =
3557
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   396
  let
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   397
    val ss =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   398
      make_ss mss mk_cong subgoal_tac loop_tacs unsafe_solvers unsafe_solvers;
4612
26764de50c74 Used THEN_ALL_NEW.
nipkow
parents: 4366
diff changeset
   399
    val solve1_tac = (subgoal_tac ss THEN_ALL_NEW (K no_tac)) 1
3557
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   400
  in DEPTH_SOLVE solve1_tac end;
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   401
4668
131989b78417 Little reorganization. Loop tactics have names now.
nipkow
parents: 4612
diff changeset
   402
fun loop_tac loop_tacs = FIRST'(map snd loop_tacs);
3557
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   403
8879
bf487b29a9a6 export generic_simp_tac;
wenzelm
parents: 8815
diff changeset
   404
(*note: may instantiate unknowns that appear also in other subgoals*)
bf487b29a9a6 export generic_simp_tac;
wenzelm
parents: 8815
diff changeset
   405
fun generic_simp_tac safe mode =
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   406
  fn (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, solvers, ...}) =>
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   407
    let
8879
bf487b29a9a6 export generic_simp_tac;
wenzelm
parents: 8815
diff changeset
   408
      val solvs = app_sols (if safe then solvers else unsafe_solvers);
4612
26764de50c74 Used THEN_ALL_NEW.
nipkow
parents: 4366
diff changeset
   409
      fun simp_loop_tac i =
26764de50c74 Used THEN_ALL_NEW.
nipkow
parents: 4366
diff changeset
   410
        asm_rewrite_goal_tac mode
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   411
          (solve_all_tac (mk_cong, subgoal_tac, loop_tacs, unsafe_solvers))
4612
26764de50c74 Used THEN_ALL_NEW.
nipkow
parents: 4366
diff changeset
   412
          mss i
8879
bf487b29a9a6 export generic_simp_tac;
wenzelm
parents: 8815
diff changeset
   413
        THEN (solvs (prems_of_mss mss) i ORELSE
4668
131989b78417 Little reorganization. Loop tactics have names now.
nipkow
parents: 4612
diff changeset
   414
              TRY ((loop_tac loop_tacs THEN_ALL_NEW simp_loop_tac) i))
4612
26764de50c74 Used THEN_ALL_NEW.
nipkow
parents: 4366
diff changeset
   415
    in simp_loop_tac end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   416
8879
bf487b29a9a6 export generic_simp_tac;
wenzelm
parents: 8815
diff changeset
   417
val          simp_tac = generic_simp_tac false (false, false, false);
bf487b29a9a6 export generic_simp_tac;
wenzelm
parents: 8815
diff changeset
   418
val      asm_simp_tac = generic_simp_tac false (false, true, false);
bf487b29a9a6 export generic_simp_tac;
wenzelm
parents: 8815
diff changeset
   419
val     full_simp_tac = generic_simp_tac false (true,  false, false);
bf487b29a9a6 export generic_simp_tac;
wenzelm
parents: 8815
diff changeset
   420
val   asm_lr_simp_tac = generic_simp_tac false (true,  true, false);
bf487b29a9a6 export generic_simp_tac;
wenzelm
parents: 8815
diff changeset
   421
val asm_full_simp_tac = generic_simp_tac false (true,  true, true);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   422
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   423
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   424
(*the abstraction over the proof state delays the dereferencing*)
4080
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   425
fun          Simp_tac i st =          simp_tac (simpset ()) i st;
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   426
fun      Asm_simp_tac i st =      asm_simp_tac (simpset ()) i st;
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   427
fun     Full_simp_tac i st =     full_simp_tac (simpset ()) i st;
4722
d2e44673c21e The new asm_lr_simp_tac is the old asm_full_simp_tac.
nipkow
parents: 4713
diff changeset
   428
fun   Asm_lr_simp_tac i st =   asm_lr_simp_tac (simpset ()) i st;
4080
7dce11095b0a new implicit simpset mechanism based on Sign.sg anytype data;
wenzelm
parents: 3728
diff changeset
   429
fun Asm_full_simp_tac i st = asm_full_simp_tac (simpset ()) i st;
406
4d4e0442b106 simpset is hidden in a functor now.
nipkow
parents: 217
diff changeset
   430
3557
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   431
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   432
5082
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
   433
(** simplification rules and conversions **)
3557
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   434
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   435
fun simp rew mode
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   436
     (Simpset {mss, mk_cong, subgoal_tac, loop_tacs, unsafe_solvers, ...}) thm =
3557
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   437
  let
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   438
    val tacf = solve_all_tac (mk_cong, subgoal_tac, loop_tacs, unsafe_solvers);
4271
3a82492e70c5 changed Pure/Sequence interface -- isatool fixseq;
wenzelm
parents: 4259
diff changeset
   439
    fun prover m th = apsome fst (Seq.pull (tacf m th));
5082
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
   440
  in rew mode prover mss thm end;
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
   441
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
   442
val simp_thm = simp Drule.rewrite_thm;
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
   443
val simp_cterm = simp Drule.rewrite_cterm;
3557
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   444
5082
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
   445
val          simplify = simp_thm (false, false, false);
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
   446
val      asm_simplify = simp_thm (false, true, false);
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
   447
val     full_simplify = simp_thm (true, false, false);
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
   448
val asm_full_simplify = simp_thm (true, true, false);
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
   449
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
   450
val          rewrite = simp_cterm (false, false, false);
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
   451
val      asm_rewrite = simp_cterm (false, true, false);
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
   452
val     full_rewrite = simp_cterm (true, false, false);
e03460289797 added XX_YY_rewrite: simpset -> cterm -> thm;
wenzelm
parents: 5028
diff changeset
   453
val asm_full_rewrite = simp_cterm (true, true, false);
3557
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   454
9546f8185c43 added simplification meta rules;
wenzelm
parents: 3551
diff changeset
   455
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   456
5886
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   457
(** concrete syntax of attributes **)
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   458
5886
0373323180f5 all modifiers turned into attributes;
wenzelm
parents: 5842
diff changeset
   459
(* add / del *)
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   460
5928
6e00a206a948 export simp_modifiers;
wenzelm
parents: 5886
diff changeset
   461
val simpN = "simp";
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   462
val congN = "cong";
5928
6e00a206a948 export simp_modifiers;
wenzelm
parents: 5886
diff changeset
   463
val addN = "add";
6e00a206a948 export simp_modifiers;
wenzelm
parents: 5886
diff changeset
   464
val delN = "del";
6911
ef0f25d0bc2d simp only: attribute, method arg;
wenzelm
parents: 6556
diff changeset
   465
val onlyN = "only";
9899
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   466
val no_asmN = "no_asm";
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   467
val no_asm_useN = "no_asm_use";
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   468
val no_asm_simpN = "no_asm_simp";
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   469
8634
3f34637cb9c0 use Attrib.add_del_args;
wenzelm
parents: 8467
diff changeset
   470
val simp_attr =
3f34637cb9c0 use Attrib.add_del_args;
wenzelm
parents: 8467
diff changeset
   471
 (Attrib.add_del_args simp_add_global simp_del_global,
3f34637cb9c0 use Attrib.add_del_args;
wenzelm
parents: 8467
diff changeset
   472
  Attrib.add_del_args simp_add_local simp_del_local);
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   473
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   474
val cong_attr =
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   475
 (Attrib.add_del_args cong_add_global cong_del_global,
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   476
  Attrib.add_del_args cong_add_local cong_del_local);
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   477
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   478
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   479
(* conversions *)
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   480
9899
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   481
local
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   482
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   483
fun conv_mode x =
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   484
  ((Args.parens (Args.$$$ no_asmN) >> K simplify ||
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   485
    Args.parens (Args.$$$ no_asm_simpN) >> K asm_simplify ||
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   486
    Args.parens (Args.$$$ no_asm_useN) >> K full_simplify ||
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   487
    Scan.succeed asm_full_simplify) |> Scan.lift) x;
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   488
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   489
fun simplified_att get =
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   490
  Attrib.syntax (conv_mode >> (fn f => Drule.rule_attribute (f o get)));
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   491
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   492
in
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   493
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   494
val simplified_attr =
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   495
  (simplified_att simpset_of, simplified_att get_local_simpset);
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   496
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   497
end;
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   498
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   499
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   500
(* setup_attrs *)
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   501
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   502
val setup_attrs = Attrib.add_attributes
9899
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   503
 [(simpN, simp_attr, "declaration of simplification rule"),
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   504
  (congN, cong_attr, "declaration of Simplifier congruence rule"),
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   505
  ("simplified", simplified_attr, "simplified rule")];
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   506
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   507
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   508
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   509
(** proof methods **)
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   510
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   511
(* simplification *)
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   512
8700
628ffca977b8 added simp_options;
wenzelm
parents: 8667
diff changeset
   513
val simp_options =
9899
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   514
 (Args.parens (Args.$$$ no_asmN) >> K simp_tac ||
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   515
  Args.parens (Args.$$$ no_asm_simpN) >> K asm_simp_tac ||
5a9081c3b869 tuned att names / msgs;
wenzelm
parents: 9861
diff changeset
   516
  Args.parens (Args.$$$ no_asm_useN) >> K full_simp_tac ||
8700
628ffca977b8 added simp_options;
wenzelm
parents: 8667
diff changeset
   517
  Scan.succeed asm_full_simp_tac);
628ffca977b8 added simp_options;
wenzelm
parents: 8667
diff changeset
   518
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   519
val cong_modifiers =
9720
3b7b72db57f1 made SML/XL happy;
wenzelm
parents: 9715
diff changeset
   520
 [Args.$$$ congN -- Args.colon >> K ((I, cong_add_local):Method.modifier),
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   521
  Args.$$$ congN -- Args.$$$ addN -- Args.colon >> K (I, cong_add_local),
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   522
  Args.$$$ congN -- Args.$$$ delN -- Args.colon >> K (I, cong_del_local)];
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   523
5928
6e00a206a948 export simp_modifiers;
wenzelm
parents: 5886
diff changeset
   524
val simp_modifiers =
8815
187547eae4c5 use Args.colon / Args.parens;
wenzelm
parents: 8727
diff changeset
   525
 [Args.$$$ simpN -- Args.colon >> K (I, simp_add_local),
187547eae4c5 use Args.colon / Args.parens;
wenzelm
parents: 8727
diff changeset
   526
  Args.$$$ simpN -- Args.$$$ addN -- Args.colon >> K (I, simp_add_local),
187547eae4c5 use Args.colon / Args.parens;
wenzelm
parents: 8727
diff changeset
   527
  Args.$$$ simpN -- Args.$$$ delN -- Args.colon >> K (I, simp_del_local),
9861
b2a6d854d6da removed 'other' modifier;
wenzelm
parents: 9720
diff changeset
   528
  Args.$$$ simpN -- Args.$$$ onlyN -- Args.colon >> K (map_local_simpset clear_ss, simp_add_local)]
b2a6d854d6da removed 'other' modifier;
wenzelm
parents: 9720
diff changeset
   529
   @ cong_modifiers;
5928
6e00a206a948 export simp_modifiers;
wenzelm
parents: 5886
diff changeset
   530
6e00a206a948 export simp_modifiers;
wenzelm
parents: 5886
diff changeset
   531
val simp_modifiers' =
8815
187547eae4c5 use Args.colon / Args.parens;
wenzelm
parents: 8727
diff changeset
   532
 [Args.$$$ addN -- Args.colon >> K (I, simp_add_local),
187547eae4c5 use Args.colon / Args.parens;
wenzelm
parents: 8727
diff changeset
   533
  Args.$$$ delN -- Args.colon >> K (I, simp_del_local),
9861
b2a6d854d6da removed 'other' modifier;
wenzelm
parents: 9720
diff changeset
   534
  Args.$$$ onlyN -- Args.colon >> K (map_local_simpset clear_ss, simp_add_local)]
b2a6d854d6da removed 'other' modifier;
wenzelm
parents: 9720
diff changeset
   535
   @ cong_modifiers;
5928
6e00a206a948 export simp_modifiers;
wenzelm
parents: 5886
diff changeset
   536
8700
628ffca977b8 added simp_options;
wenzelm
parents: 8667
diff changeset
   537
fun simp_args more_mods =
628ffca977b8 added simp_options;
wenzelm
parents: 8667
diff changeset
   538
  Method.sectioned_args (Args.bang_facts -- Scan.lift simp_options) (more_mods @ simp_modifiers');
628ffca977b8 added simp_options;
wenzelm
parents: 8667
diff changeset
   539
8170
4b9451fae406 simp_all method;
wenzelm
parents: 8168
diff changeset
   540
8700
628ffca977b8 added simp_options;
wenzelm
parents: 8667
diff changeset
   541
fun simp_method (prems, tac) ctxt = Method.METHOD (fn facts =>
628ffca977b8 added simp_options;
wenzelm
parents: 8667
diff changeset
   542
  ALLGOALS (Method.insert_tac (prems @ facts)) THEN
628ffca977b8 added simp_options;
wenzelm
parents: 8667
diff changeset
   543
    (CHANGED o ALLGOALS o tac) (get_local_simpset ctxt));
628ffca977b8 added simp_options;
wenzelm
parents: 8667
diff changeset
   544
628ffca977b8 added simp_options;
wenzelm
parents: 8667
diff changeset
   545
fun simp_method' (prems, tac) ctxt = Method.METHOD (fn facts =>
628ffca977b8 added simp_options;
wenzelm
parents: 8667
diff changeset
   546
  HEADGOAL (Method.insert_tac (prems @ facts) THEN' (CHANGED oo tac) (get_local_simpset ctxt)));
9715
5705a04d24ea proper cong setup;
wenzelm
parents: 9513
diff changeset
   547
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   548
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   549
(* setup_methods *)
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   550
8467
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
   551
fun setup_methods more_mods = Method.add_methods
8700
628ffca977b8 added simp_options;
wenzelm
parents: 8667
diff changeset
   552
 [(simpN, simp_args more_mods simp_method', "simplification"),
628ffca977b8 added simp_options;
wenzelm
parents: 8667
diff changeset
   553
  ("simp_all", simp_args more_mods simp_method, "simplification (all goals)")];
5842
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   554
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   555
1a708aa63ff0 local simpset theory data;
wenzelm
parents: 5082
diff changeset
   556
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   557
(** theory setup **)
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   558
8467
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
   559
val setup = [GlobalSimpset.init, LocalSimpset.init, setup_attrs];
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
   560
fun method_setup mods = [setup_methods mods];
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   561
8228
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   562
fun easy_setup reflect trivs =
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   563
  let
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   564
    val trivialities = Drule.reflexive_thm :: trivs;
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   565
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   566
    fun unsafe_solver_tac prems = FIRST' [resolve_tac (trivialities @ prems), assume_tac];
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   567
    val unsafe_solver = mk_solver "easy unsafe" unsafe_solver_tac;
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   568
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   569
    (*no premature instantiation of variables during simplification*)
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   570
    fun safe_solver_tac prems = FIRST' [match_tac (trivialities @ prems), eq_assume_tac];
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   571
    val safe_solver = mk_solver "easy safe" safe_solver_tac;
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   572
8243
5db67376df7d easy_setup: fixed mksimps;
wenzelm
parents: 8228
diff changeset
   573
    fun mk_eq thm =
8228
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   574
      if Logic.is_equals (Thm.concl_of thm) then [thm]
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   575
      else [thm RS reflect] handle THM _ => [];
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   576
8243
5db67376df7d easy_setup: fixed mksimps;
wenzelm
parents: 8228
diff changeset
   577
    fun mksimps thm = mk_eq (Drule.forall_elim_vars (#maxidx (Thm.rep_thm thm) + 1) thm);
5db67376df7d easy_setup: fixed mksimps;
wenzelm
parents: 8228
diff changeset
   578
8228
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   579
    fun init_ss thy =
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   580
      (simpset_ref_of thy :=
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   581
        empty_ss setsubgoaler asm_simp_tac
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   582
        setSSolver safe_solver
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   583
        setSolver unsafe_solver
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   584
        setmksimps mksimps; thy);
8467
58dbeea60bb8 export change_global_ss, change_local_ss;
wenzelm
parents: 8382
diff changeset
   585
  in setup @ method_setup [] @ [init_ss] end;
8228
8283e416b680 added easy_setup;
wenzelm
parents: 8170
diff changeset
   586
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   587
8667
4230d17073ea print_simpset / print_claset command;
wenzelm
parents: 8634
diff changeset
   588
4230d17073ea print_simpset / print_claset command;
wenzelm
parents: 8634
diff changeset
   589
(** outer syntax **)
4230d17073ea print_simpset / print_claset command;
wenzelm
parents: 8634
diff changeset
   590
4230d17073ea print_simpset / print_claset command;
wenzelm
parents: 8634
diff changeset
   591
val print_simpsetP =
4230d17073ea print_simpset / print_claset command;
wenzelm
parents: 8634
diff changeset
   592
  OuterSyntax.improper_command "print_simpset" "print context of Simplifier"
4230d17073ea print_simpset / print_claset command;
wenzelm
parents: 8634
diff changeset
   593
    OuterSyntax.Keyword.diag
9513
8531c18d9181 unknown_theory/proof/context;
wenzelm
parents: 9446
diff changeset
   594
    (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_context o (Toplevel.keep
9010
ce78dc5e1a73 Toplevel.no_timing;
wenzelm
parents: 8879
diff changeset
   595
      (Toplevel.node_case print_simpset (print_local_simpset o Proof.context_of)))));
8667
4230d17073ea print_simpset / print_claset command;
wenzelm
parents: 8634
diff changeset
   596
4230d17073ea print_simpset / print_claset command;
wenzelm
parents: 8634
diff changeset
   597
val _ = OuterSyntax.add_parsers [print_simpsetP];
4230d17073ea print_simpset / print_claset command;
wenzelm
parents: 8634
diff changeset
   598
1243
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
   599
end;
4795
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   600
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   601
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   602
structure BasicSimplifier: BASIC_SIMPLIFIER = Simplifier;
721b532ada7a tuned comments;
wenzelm
parents: 4784
diff changeset
   603
open BasicSimplifier;