src/Provers/simplifier.ML
author wenzelm
Tue, 22 Jul 1997 18:46:44 +0200
changeset 3551 7c013a617813
parent 3537 79ac9b475621
child 3557 9546f8185c43
permissions -rw-r--r--
added print_ss; improved merge;
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.
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
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
    10
  setsubgoaler setloop addloop setSSolver addSSolver setSolver
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
    11
  addSolver setmksimps addsimps delsimps addeqcongs deleqcongs
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
    12
  settermless addsimprocs delsimprocs;
2567
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
    13
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
signature SIMPLIFIER =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
sig
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    17
  type simproc
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    18
  val mk_simproc: string -> cterm list -> (Sign.sg -> term -> thm option) -> simproc
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    19
  val conv_prover: (term * term -> term) -> thm -> (thm -> thm)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    20
    -> tactic -> (int -> tactic) -> Sign.sg -> term -> term -> thm	(* FIXME move?, rename? *)
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,
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
    25
    subgoal_tac:        simpset -> int -> tactic,
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
    26
    loop_tac:                      int -> tactic,
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
    27
           finish_tac: thm list -> int -> tactic,
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
    28
    unsafe_finish_tac: thm list -> int -> tactic};
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
    29
  val print_ss: simpset -> unit
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    30
  val setsubgoaler: simpset *  (simpset -> int -> tactic) -> simpset
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    31
  val setloop:      simpset *             (int -> tactic) -> simpset
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    32
  val addloop:      simpset *             (int -> tactic) -> simpset
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    33
  val setSSolver:   simpset * (thm list -> int -> tactic) -> simpset
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    34
  val addSSolver:   simpset * (thm list -> int -> tactic) -> simpset
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    35
  val setSolver:    simpset * (thm list -> int -> tactic) -> simpset
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    36
  val addSolver:    simpset * (thm list -> int -> tactic) -> simpset
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    37
  val setmksimps:  simpset * (thm -> thm list) -> simpset
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    38
  val settermless: simpset * (term * term -> bool) -> simpset
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    39
  val addsimps:    simpset * thm list -> simpset
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    40
  val delsimps:    simpset * thm list -> simpset
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    41
  val addeqcongs:  simpset * thm list -> simpset
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    42
  val deleqcongs:  simpset * thm list -> simpset
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    43
  val addsimprocs: simpset * simproc list -> simpset
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    44
  val delsimprocs: simpset * simproc list -> simpset
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    45
  val merge_ss:    simpset * simpset -> simpset
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    46
  val prems_of_ss: simpset -> thm list
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    47
  val simpset:     simpset ref
1243
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
    48
  val Addsimps: thm list -> unit
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
    49
  val Delsimps: thm list -> unit
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    50
  val Addsimprocs: simproc list -> unit
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    51
  val Delsimprocs: simproc list -> unit
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    52
  val               simp_tac: simpset -> int -> tactic
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    53
  val           asm_simp_tac: simpset -> int -> tactic
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    54
  val          full_simp_tac: simpset -> int -> tactic
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    55
  val      asm_full_simp_tac: simpset -> int -> tactic
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    56
  val safe_asm_full_simp_tac: simpset -> int -> tactic
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    57
  val               Simp_tac:            int -> tactic
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    58
  val           Asm_simp_tac:            int -> tactic
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    59
  val          Full_simp_tac:            int -> tactic
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
    60
  val      Asm_full_simp_tac:            int -> tactic
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    61
end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    62
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    63
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    64
structure Simplifier: SIMPLIFIER =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    67
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    68
(** simplification procedures **)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    69
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    70
(* datatype simproc *)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    71
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    72
datatype simproc =
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
    73
  Simproc of string * cterm list * (Sign.sg -> term -> thm option) * stamp;
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    74
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
    75
fun mk_simproc name lhss proc = Simproc (name, lhss, proc, stamp ());
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
    76
fun rep_simproc (Simproc args) = args;
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    77
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    78
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    79
(* generic conversion prover *)		(* FIXME move?, rename? *)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    80
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    81
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
    82
  let
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    83
    val X = Free (gensym "X.", fastype_of t);
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    84
    val goal = Logic.mk_implies (mk_eqv (X, t), mk_eqv (X, u));
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    85
    val pre_result =
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    86
      prove_goalw_cterm [] (cterm_of sg goal)   (*goal: X=t ==> X=u*)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    87
        (fn prems => [
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    88
          expand_tac,				(*expand u*)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    89
          ALLGOALS (cut_facts_tac prems),
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    90
          ALLGOALS norm_tac]);			(*normalize both t and u*)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    91
  in
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    92
    mk_meta_eq (eqv_refl RS pre_result)         (*final result: t==u*)
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    93
  end
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    94
  handle ERROR => error ("The error(s) above occurred while trying to prove " ^
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    95
    (string_of_cterm (cterm_of sg (mk_eqv (t, u)))));
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    96
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    97
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
    98
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
    99
(** simplification sets **)
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   100
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   101
(* type simpset *)
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   102
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   103
datatype simpset =
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   104
  Simpset of {
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   105
    mss: meta_simpset,
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   106
    subgoal_tac:        simpset -> int -> tactic,
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   107
    loop_tac:                      int -> tactic,
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   108
           finish_tac: thm list -> int -> tactic,
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   109
    unsafe_finish_tac: thm list -> int -> tactic};
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   110
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   111
fun make_ss (mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac) =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   112
  Simpset {mss = mss, subgoal_tac = subgoal_tac, loop_tac = loop_tac,
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   113
    finish_tac = finish_tac, unsafe_finish_tac = unsafe_finish_tac};
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   114
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   115
val empty_ss =
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   116
  make_ss (Thm.empty_mss, K (K no_tac), K no_tac, K (K no_tac), K (K no_tac));
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   117
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   118
fun rep_ss (Simpset args) = args;
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   119
fun prems_of_ss (Simpset {mss, ...}) = Thm.prems_of_mss mss;
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   120
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   121
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   122
(* print simpsets *)
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   123
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   124
fun print_ss ss =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   125
  let
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   126
    val Simpset {mss, ...} = ss;
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   127
    val {simps, procs, congs} = Thm.dest_mss mss;
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   128
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   129
    val pretty_thms = map Display.pretty_thm;
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   130
    fun pretty_proc (name, lhss) =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   131
      Pretty.big_list (name ^ ":") (map Display.pretty_cterm lhss);
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   132
  in
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   133
    Pretty.writeln (Pretty.big_list "simplification rules:" (pretty_thms simps));
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   134
    Pretty.writeln (Pretty.big_list "simplification procedures:" (map pretty_proc procs));
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   135
    Pretty.writeln (Pretty.big_list "congruences:" (pretty_thms congs))
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   136
  end;
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   137
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   138
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   139
(* extend simpsets *)
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   140
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   141
fun (Simpset {mss, subgoal_tac = _, loop_tac, finish_tac, unsafe_finish_tac})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   142
    setsubgoaler subgoal_tac =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   143
  make_ss (mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac);
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   144
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   145
fun (Simpset {mss, subgoal_tac, loop_tac = _, finish_tac, unsafe_finish_tac})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   146
    setloop loop_tac =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   147
  make_ss (mss, subgoal_tac, DETERM o loop_tac, finish_tac, unsafe_finish_tac);
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   148
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   149
fun (Simpset {mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   150
    addloop tac =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   151
  make_ss (mss, subgoal_tac, loop_tac ORELSE' (DETERM o tac), finish_tac, unsafe_finish_tac);
2567
7a28e02e10b7 added addloop (and also documentation of addsolver
oheimb
parents: 2521
diff changeset
   152
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   153
fun (Simpset {mss, subgoal_tac, loop_tac, finish_tac = _, unsafe_finish_tac})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   154
    setSSolver finish_tac =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   155
  make_ss (mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac);
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   156
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   157
fun (Simpset {mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   158
    addSSolver tac =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   159
  make_ss (mss, subgoal_tac, loop_tac, fn hyps => finish_tac hyps ORELSE' tac hyps,
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   160
    unsafe_finish_tac);
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   161
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   162
fun (Simpset {mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac = _})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   163
    setSolver unsafe_finish_tac =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   164
  make_ss (mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac);
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   165
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   166
fun (Simpset {mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   167
    addSolver tac =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   168
  make_ss (mss, subgoal_tac, loop_tac, finish_tac,
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   169
    fn hyps => unsafe_finish_tac hyps ORELSE' tac hyps);
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   170
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   171
fun (Simpset {mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   172
    setmksimps mk_simps =
2645
9d3a3e62bf34 mk_rews: automatically includes strip_shyps, zero_var_indexes;
wenzelm
parents: 2629
diff changeset
   173
  make_ss (Thm.set_mk_rews (mss, map (Thm.strip_shyps o Drule.zero_var_indexes) o mk_simps),
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   174
    subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac);
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   175
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   176
fun (Simpset {mss, subgoal_tac, loop_tac,  finish_tac, unsafe_finish_tac})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   177
    settermless termless =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   178
  make_ss (Thm.set_termless (mss, termless), subgoal_tac, loop_tac,
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   179
    finish_tac, unsafe_finish_tac);
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   180
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   181
fun (Simpset {mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   182
    addsimps rews =
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   183
  let val rews' = flat (map (Thm.mk_rews_of_mss mss) rews) in
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   184
    make_ss (Thm.add_simps (mss, rews'), subgoal_tac, loop_tac,
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   185
      finish_tac, unsafe_finish_tac)
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   186
  end;
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   187
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   188
fun (Simpset {mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   189
    delsimps rews =
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   190
  let val rews' = flat (map (Thm.mk_rews_of_mss mss) rews) in
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   191
    make_ss (Thm.del_simps (mss, rews'), subgoal_tac, loop_tac,
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   192
      finish_tac, unsafe_finish_tac)
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   193
  end;
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   194
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   195
fun (Simpset {mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   196
    addeqcongs newcongs =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   197
  make_ss (Thm.add_congs (mss, newcongs), subgoal_tac, loop_tac,
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   198
    finish_tac, unsafe_finish_tac);
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   199
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   200
fun (Simpset {mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   201
    deleqcongs oldcongs =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   202
  make_ss (Thm.del_congs (mss, oldcongs), subgoal_tac, loop_tac,
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   203
    finish_tac, unsafe_finish_tac);
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   204
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   205
fun (Simpset {mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   206
    addsimprocs simprocs =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   207
  make_ss
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   208
    (Thm.add_simprocs (mss, map rep_simproc simprocs),
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   209
      subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac);
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   210
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   211
fun (Simpset {mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac})
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   212
    delsimprocs simprocs =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   213
  make_ss
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   214
    (Thm.del_simprocs (mss, map rep_simproc simprocs),
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   215
      subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac);
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   216
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   217
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   218
(* merge simpsets *)	(*NOTE: ignores tactics of 2nd simpset*)
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   219
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   220
fun merge_ss
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   221
   (Simpset {mss = mss1, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac},
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   222
    Simpset {mss = mss2, ...}) =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   223
  make_ss (Thm.merge_mss (mss1, mss2),
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   224
    subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac);
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   225
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   226
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   227
(* the current simpset *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   228
1243
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
   229
val simpset = ref empty_ss;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   230
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   231
fun Addsimps rews = (simpset := ! simpset addsimps rews);
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   232
fun Delsimps rews = (simpset := ! simpset delsimps rews);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   233
2509
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   234
fun Addsimprocs procs = (simpset := ! simpset addsimprocs procs);
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   235
fun Delsimprocs procs = (simpset := ! simpset delsimprocs procs);
0a7169d89b7a added termless parameter;
wenzelm
parents: 2503
diff changeset
   236
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   237
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   238
(** simplification tactics **)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   239
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   240
fun NEWSUBGOALS tac tacf st0 =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   241
  st0 |> (tac THEN (fn st1 => tacf (nprems_of st1 - nprems_of st0) st1));
1
c6a6e3db5353 changed addcongs to addeqcongs in simplifier.ML
nipkow
parents: 0
diff changeset
   242
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   243
(*not totally safe: may instantiate unknowns that appear also in other subgoals*)
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   244
fun basic_gen_simp_tac mode =
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   245
  fn (Simpset {mss, subgoal_tac, loop_tac, finish_tac, unsafe_finish_tac}) =>
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   246
    let
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   247
      fun solve_all_tac mss =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   248
        let
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   249
          val ss =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   250
            make_ss (mss, subgoal_tac, loop_tac, unsafe_finish_tac, unsafe_finish_tac);
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   251
          val solve1_tac =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   252
            NEWSUBGOALS (subgoal_tac ss 1) (fn n => if n < 0 then all_tac else no_tac)
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   253
        in DEPTH_SOLVE solve1_tac end;
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   254
1512
ce37c64244c0 Elimination of fully-functorial style.
paulson
parents: 1260
diff changeset
   255
      fun simp_loop_tac i thm =
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   256
        (asm_rewrite_goal_tac mode solve_all_tac mss i THEN
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   257
          (finish_tac (prems_of_mss mss) i ORELSE looper i)) thm
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   258
      and allsimp i n = EVERY (map (fn j => simp_loop_tac (i + j)) (n downto 0))
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   259
      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
   260
  in simp_loop_tac end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   261
3551
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   262
fun gen_simp_tac mode (ss as Simpset {unsafe_finish_tac, ...}) =
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   263
  basic_gen_simp_tac mode (ss setSSolver unsafe_finish_tac);
7c013a617813 added print_ss;
wenzelm
parents: 3537
diff changeset
   264
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   265
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   266
val          simp_tac = gen_simp_tac (false, false);
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   267
val      asm_simp_tac = gen_simp_tac (false, true);
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   268
val     full_simp_tac = gen_simp_tac (true,  false);
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   269
val asm_full_simp_tac = gen_simp_tac (true,  true);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   270
2629
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   271
(*not totally safe: may instantiate unknowns that appear also in other subgoals*)
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   272
val safe_asm_full_simp_tac = basic_gen_simp_tac (true, true);
b442786d4469 added deleqcongs, richer rep_ss
oheimb
parents: 2567
diff changeset
   273
2503
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   274
fun          Simp_tac i =          simp_tac (! simpset) i;
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   275
fun      Asm_simp_tac i =      asm_simp_tac (! simpset) i;
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   276
fun     Full_simp_tac i =     full_simp_tac (! simpset) i;
7590fd5ce3c7 cleaned up (real changes next time);
wenzelm
parents: 1770
diff changeset
   277
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
   278
1243
fa09705a5890 added global simpset
clasohm
parents: 983
diff changeset
   279
end;