src/Provers/simplifier.ML
author oheimb
Fri, 31 Jan 1997 15:54:00 +0100
changeset 2567 7a28e02e10b7
parent 2521 b7dd670cfe3a
child 2629 b442786d4469
permissions -rw-r--r--
added addloop (and also documentation of addsolver
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$
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
     3
    Author:     Tobias Nipkow
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
     4
    Copyright   1993  TU Munich
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
     5
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
     6
Generic simplifier, suitable for most logics.
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
     7
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
     8
TODO:
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
     9
  - stamps to identify funs / tacs
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    10
  - merge: fail if incompatible funs
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    11
  - improve merge
1
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
    12
*)
1260
c76ac4a9dc2b renamed SS to Simpset; fixed bug in merge_ss
clasohm
parents: 1243
diff changeset
    13
2567
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
    14
infix 4 setloop addloop setsolver addsolver 
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
    15
        setsubgoaler setmksimps
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
    16
	addsimps addeqcongs delsimps 
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
    17
	settermless addsimprocs delsimprocs;
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
    18
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
signature SIMPLIFIER =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
sig
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    22
  type simproc
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    23
  val mk_simproc: string -> cterm list -> (Sign.sg -> term -> thm option) -> simproc
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    24
  val name_of_simproc: simproc -> string
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    25
  val conv_prover: (term * term -> term) -> thm -> (thm -> thm)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    26
    -> tactic -> (int -> tactic) -> Sign.sg -> term -> term -> thm	(* FIXME move?, rename? *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
  type simpset
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    28
  val empty_ss: simpset
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    29
  val rep_ss: simpset -> {simps: thm list, procs: string list, congs: thm list}
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    30
  val prems_of_ss: simpset -> thm list
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    31
  val setloop: simpset * (int -> tactic) -> simpset
2567
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
    32
  val addloop: simpset * (int -> tactic) -> simpset
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    33
  val setsolver: simpset * (thm list -> int -> tactic) -> simpset
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    34
  val addsolver: simpset * (thm list -> int -> tactic) -> simpset
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    35
  val setsubgoaler: simpset * (simpset -> int -> tactic) -> simpset
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    36
  val setmksimps: simpset * (thm -> thm list) -> simpset
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    37
  val settermless: simpset * (term * term -> bool) -> simpset
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
  val addsimps: simpset * thm list -> simpset
88
9df4dfedee01 added infix delsimps
nipkow
parents: 17
diff changeset
    39
  val delsimps: simpset * thm list -> simpset
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    40
  val addsimprocs: simpset * simproc list -> simpset
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    41
  val delsimprocs: simpset * simproc list -> simpset
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    42
  val addeqcongs: simpset * thm list -> simpset
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
  val merge_ss: simpset * simpset -> simpset
1243
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
    44
  val simpset: simpset ref
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
    45
  val Addsimps: thm list -> unit
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
    46
  val Delsimps: thm list -> unit
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    47
  val Addsimprocs: simproc list -> unit
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    48
  val Delsimprocs: simproc list -> unit
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    49
  val          simp_tac: simpset -> int -> tactic
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    50
  val      asm_simp_tac: simpset -> int -> tactic
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    51
  val     full_simp_tac: simpset -> int -> tactic
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    52
  val asm_full_simp_tac: simpset -> int -> tactic
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    53
  val          Simp_tac: int -> tactic
1676
db29ab9c1490 *** empty log message ***
oheimb
parents: 1512
diff changeset
    54
  val      Asm_simp_tac: int -> tactic
db29ab9c1490 *** empty log message ***
oheimb
parents: 1512
diff changeset
    55
  val     Full_simp_tac: int -> tactic
1243
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
    56
  val Asm_full_simp_tac: int -> tactic
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    58
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    59
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    60
structure Simplifier: SIMPLIFIER =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    61
struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    62
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    63
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    64
(** simplification procedures **)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    65
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    66
(* datatype simproc *)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    67
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    68
datatype simproc =
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    69
  Simproc of {
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    70
    name: string,
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    71
    procs: (Sign.sg * term * (Sign.sg -> term -> thm option) * stamp) list}
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    72
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    73
(* FIXME stamps!? *)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    74
fun eq_simproc (Simproc {name = name1, ...}, Simproc {name = name2, ...}) =
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    75
  (name1 = name2);
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    76
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    77
fun mk_simproc name lhss proc =
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    78
  let
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    79
    fun mk_proc lhs =
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    80
      (#sign (Thm.rep_cterm lhs), Logic.varify (term_of lhs), proc, stamp ());
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    81
  in
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    82
    Simproc {name = name, procs = map mk_proc lhss}
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    83
  end;
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    84
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    85
fun name_of_simproc (Simproc {name, ...}) = name;
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    86
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    87
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    88
(* generic conversion prover *)		(* FIXME move?, rename? *)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    89
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    90
fun conv_prover mk_eqv eqv_refl mk_meta_eq expand_tac norm_tac sg t u =
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    91
  let
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    92
    val X = Free (gensym "X.", fastype_of t);
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    93
    val goal = Logic.mk_implies (mk_eqv (X, t), mk_eqv (X, u));
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    94
    val pre_result =
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    95
      prove_goalw_cterm [] (cterm_of sg goal)   (*goal: X=t ==> X=u*)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    96
        (fn prems => [
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    97
          expand_tac,				(*expand u*)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    98
          ALLGOALS (cut_facts_tac prems),
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    99
          ALLGOALS norm_tac]);			(*normalize both t and u*)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   100
  in
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   101
    mk_meta_eq (eqv_refl RS pre_result)         (*final result: t==u*)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   102
  end
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   103
  handle ERROR => error ("The error(s) above occurred while trying to prove " ^
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   104
    (string_of_cterm (cterm_of sg (mk_eqv (t, u)))));
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   105
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   106
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   107
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   108
(** simplification sets **)
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   109
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   110
(* type simpset *)
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   111
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   112
datatype simpset =
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   113
  Simpset of {
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   114
    mss: meta_simpset,
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   115
    simps: thm list,
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   116
    procs: simproc list,
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   117
    congs: thm list,
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   118
    subgoal_tac: simpset -> int -> tactic,
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   119
    finish_tac: thm list -> int -> tactic,
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   120
    loop_tac: int -> tactic};
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   121
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   122
fun make_ss (mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac) =
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   123
  Simpset {mss = mss, simps = simps, procs = procs, congs = congs,
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   124
    subgoal_tac = subgoal_tac, finish_tac = finish_tac,
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   125
    loop_tac = loop_tac};
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   126
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   127
val empty_ss =
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   128
  make_ss (Thm.empty_mss, [], [], [], K (K no_tac), K (K no_tac), K no_tac);
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   129
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   130
fun rep_ss (Simpset {simps, procs, congs, ...}) =
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   131
  {simps = simps, procs = map name_of_simproc procs, congs = congs};
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   132
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   133
fun prems_of_ss (Simpset {mss, ...}) = Thm.prems_of_mss mss;
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   134
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   135
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   136
(* extend simpsets *)
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   137
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   138
fun (Simpset {mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac = _})
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   139
    setloop loop_tac =
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   140
  make_ss (mss, simps, procs, congs, subgoal_tac, finish_tac, DETERM o loop_tac);
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   141
2567
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
   142
fun (Simpset {mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac})
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
   143
    addloop tac =
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
   144
  make_ss (mss, simps, procs, congs, subgoal_tac, finish_tac, 
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
   145
    loop_tac ORELSE' (DETERM o tac));
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
   146
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   147
fun (Simpset {mss, simps, procs, congs, subgoal_tac, finish_tac = _, loop_tac})
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   148
    setsolver finish_tac =
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   149
  make_ss (mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac);
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   150
2567
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
   151
fun (Simpset {mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac})
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   152
    addsolver tac =
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   153
  make_ss (mss, simps, procs, congs, subgoal_tac,
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   154
    fn hyps => finish_tac hyps ORELSE' tac hyps, loop_tac);
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   155
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   156
fun (Simpset {mss, simps, procs, congs, subgoal_tac = _, finish_tac, loop_tac})
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   157
    setsubgoaler subgoal_tac =
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   158
  make_ss (mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac);
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   159
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   160
fun (Simpset {mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac})
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   161
    setmksimps mk_simps =
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   162
  make_ss (Thm.set_mk_rews (mss, mk_simps), simps, procs, congs,
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   163
    subgoal_tac, finish_tac, loop_tac);
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   164
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   165
fun (Simpset {mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac})
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   166
    settermless termless =
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   167
  make_ss (Thm.set_termless (mss, termless), simps, procs, congs,
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   168
    subgoal_tac, finish_tac, loop_tac);
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   169
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   170
fun (Simpset {mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac})
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   171
    addsimps rews =
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   172
  let val rews' = flat (map (Thm.mk_rews_of_mss mss) rews) in
2521
b7dd670cfe3a addsimps, addeqcongs: replaced @ by gen_union;
wenzelm
parents: 2509
diff changeset
   173
    make_ss (Thm.add_simps (mss, rews'), gen_union eq_thm (rews', simps),
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   174
      procs, congs, subgoal_tac, finish_tac, loop_tac)
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   175
  end;
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   176
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   177
fun (Simpset {mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac})
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   178
    delsimps rews =
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   179
  let val rews' = flat (map (Thm.mk_rews_of_mss mss) rews) in
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   180
    make_ss (Thm.del_simps (mss, rews'),
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   181
      foldl (gen_rem eq_thm) (simps, rews'),
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   182
      procs, congs, subgoal_tac, finish_tac, loop_tac)
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   183
  end;
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   184
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   185
fun (Simpset {mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac})
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   186
    addeqcongs newcongs =
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   187
  make_ss (Thm.add_congs (mss, newcongs),
2521
b7dd670cfe3a addsimps, addeqcongs: replaced @ by gen_union;
wenzelm
parents: 2509
diff changeset
   188
    simps, procs, gen_union eq_thm (newcongs, congs),
b7dd670cfe3a addsimps, addeqcongs: replaced @ by gen_union;
wenzelm
parents: 2509
diff changeset
   189
    subgoal_tac, finish_tac, loop_tac);
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   190
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   191
fun addsimproc ((Simpset {mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac}),
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   192
      simproc as Simproc {name = _, procs = procs'}) =
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   193
  make_ss (Thm.add_simprocs (mss, procs'),
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   194
    simps, gen_ins eq_simproc (simproc, procs),
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   195
    congs, subgoal_tac, finish_tac, loop_tac);
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   196
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   197
val op addsimprocs = foldl addsimproc;
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   198
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   199
fun delsimproc ((Simpset {mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac}),
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   200
      simproc as Simproc {name = _, procs = procs'}) =
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   201
  make_ss (Thm.del_simprocs (mss, procs'),
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   202
    simps, gen_rem eq_simproc (procs, simproc),
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   203
    congs, subgoal_tac, finish_tac, loop_tac);
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   204
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   205
val op delsimprocs = foldl delsimproc;
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   206
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   207
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   208
(* merge simpsets *)
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   209
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   210
(*prefers first simpset (FIXME improve?)*)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   211
fun merge_ss (Simpset {mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac},
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   212
    Simpset {simps = simps2, procs = procs2, congs = congs2, ...}) =
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   213
  let
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   214
    val simps' = gen_union eq_thm (simps, simps2);
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   215
    val procs' = gen_union eq_simproc (procs, procs2);
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   216
    val congs' = gen_union eq_thm (congs, congs2);
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   217
    val mss' = Thm.set_mk_rews (empty_mss, Thm.mk_rews_of_mss mss);
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   218
    val mss' = Thm.add_simps (mss', simps');
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   219
    val mss' = Thm.add_congs (mss', congs');
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   220
  in
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   221
    make_ss (mss', simps', procs', congs', subgoal_tac, finish_tac, loop_tac)
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   222
  end;
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   223
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   224
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   225
(* the current simpset *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   226
1243
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
   227
val simpset = ref empty_ss;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   228
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   229
fun Addsimps rews = (simpset := ! simpset addsimps rews);
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   230
fun Delsimps rews = (simpset := ! simpset delsimps rews);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   231
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   232
fun Addsimprocs procs = (simpset := ! simpset addsimprocs procs);
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   233
fun Delsimprocs procs = (simpset := ! simpset delsimprocs procs);
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   234
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   235
1243
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
   236
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   237
(** simplification tactics **)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   238
1
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
   239
fun NEWSUBGOALS tac tacf =
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   240
  STATE (fn state0 =>
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   241
    tac THEN STATE (fn state1 => tacf (nprems_of state1 - nprems_of state0)));
1
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
   242
217
c972c57e7762 got rid of METAHYPS due to the change of the basic simplification routines
nipkow
parents: 146
diff changeset
   243
fun gen_simp_tac mode =
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   244
  fn (Simpset {mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac}) =>
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   245
  let fun solve_all_tac mss =
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   246
        let val ss =
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   247
              make_ss (mss, simps, procs, congs, subgoal_tac, finish_tac, loop_tac);
1
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
   248
            val solve1_tac =
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
   249
              NEWSUBGOALS (subgoal_tac ss 1)
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
   250
                          (fn n => if n<0 then all_tac else no_tac)
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
   251
        in DEPTH_SOLVE(solve1_tac) end
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   252
1512
ce37c64244c0 Elimination of fully-functorial style.
paulson
parents: 1260
diff changeset
   253
      fun simp_loop_tac i thm =
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   254
          (asm_rewrite_goal_tac mode solve_all_tac mss i THEN
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   255
           (finish_tac (prems_of_mss mss) i  ORELSE  looper i))  thm
1
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
   256
      and allsimp i n = EVERY(map (fn j => simp_loop_tac (i+j)) (n downto 0))
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
   257
      and looper i = TRY(NEWSUBGOALS (loop_tac i) (allsimp i))
217
c972c57e7762 got rid of METAHYPS due to the change of the basic simplification routines
nipkow
parents: 146
diff changeset
   258
  in simp_loop_tac end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   259
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   260
val          simp_tac = gen_simp_tac (false, false);
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   261
val      asm_simp_tac = gen_simp_tac (false, true);
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   262
val     full_simp_tac = gen_simp_tac (true,  false);
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   263
val asm_full_simp_tac = gen_simp_tac (true,  true);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   264
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   265
fun          Simp_tac i =          simp_tac (! simpset) i;
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   266
fun      Asm_simp_tac i =      asm_simp_tac (! simpset) i;
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   267
fun     Full_simp_tac i =     full_simp_tac (! simpset) i;
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   268
fun Asm_full_simp_tac i = asm_full_simp_tac (! simpset) i;
406
4d4e0442b106 simpset is hidden in a functor now.
nipkow
parents: 217
diff changeset
   269
1243
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
   270
end;