src/Provers/clasimp.ML
author wenzelm
Tue, 05 Sep 2000 18:50:12 +0200
changeset 9860 5c5efed691b9
parent 9805 10b617bdd028
child 9893 93d2fde0306c
permissions -rw-r--r--
added 'iff' declarations;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9772
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
     1
(*  Title:      Provers/clasimp.ML
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
     2
    ID:         $Id$
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
     3
    Author:     David von Oheimb, TU Muenchen
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
     4
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
     5
Combination of classical reasoner and simplifier (depends on
8469
482c301041b4 include Splitter.split_modifiers;
wenzelm
parents: 8168
diff changeset
     6
simplifier.ML, splitter.ML classical.ML, blast.ML).
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
     7
*)
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
     8
9860
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
     9
infix 4 addSIs2 addSEs2 addSDs2 addIs2 addEs2 addDs2 addsimps2 delsimps2
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    10
  addSss addss addIffs delIffs;
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    11
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    12
signature CLASIMP_DATA =
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    13
sig
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    14
  structure Simplifier: SIMPLIFIER
8469
482c301041b4 include Splitter.split_modifiers;
wenzelm
parents: 8168
diff changeset
    15
  structure Splitter: SPLITTER
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    16
  structure Classical: CLASSICAL
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    17
  structure Blast: BLAST
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    18
  sharing type Classical.claset = Blast.claset
9860
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    19
  val dest_Trueprop: term -> term
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    20
  val not_const: term
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    21
  val iff_const: term
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    22
  val notE: thm
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    23
  val iffD1: thm
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    24
  val iffD2: thm
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    25
  val cla_make_elim: thm -> thm
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    26
end
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    27
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    28
signature CLASIMP =
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    29
sig
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    30
  include CLASIMP_DATA
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    31
  type claset
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    32
  type simpset
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    33
  type clasimpset
9860
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    34
  val addSIs2: clasimpset * thm list -> clasimpset
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    35
  val addSEs2: clasimpset * thm list -> clasimpset
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    36
  val addSDs2: clasimpset * thm list -> clasimpset
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    37
  val addIs2: clasimpset * thm list -> clasimpset
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    38
  val addEs2: clasimpset * thm list -> clasimpset
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    39
  val addDs2: clasimpset * thm list -> clasimpset
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    40
  val addsimps2: clasimpset * thm list -> clasimpset
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    41
  val delsimps2: clasimpset * thm list -> clasimpset
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    42
  val addSss: claset * simpset -> claset
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    43
  val addss: claset * simpset -> claset
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    44
  val addIffs: clasimpset * thm list -> clasimpset
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    45
  val delIffs: clasimpset * thm list -> clasimpset
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    46
  val AddIffs: thm list -> unit
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    47
  val DelIffs: thm list -> unit
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    48
  val CLASIMPSET: (clasimpset -> tactic) -> tactic
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    49
  val CLASIMPSET': (clasimpset -> 'a -> tactic) -> 'a -> tactic
5483
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    50
  val clarsimp_tac: clasimpset -> int -> tactic
9860
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    51
  val Clarsimp_tac: int -> tactic
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    52
  val mk_auto_tac: clasimpset -> int -> int -> tactic
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    53
  val auto_tac: clasimpset -> tactic
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    54
  val Auto_tac: tactic
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    55
  val auto: unit -> unit
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    56
  val force_tac: clasimpset  -> int -> tactic
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    57
  val Force_tac: int -> tactic
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    58
  val force: int -> unit
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    59
  val fast_simp_tac: clasimpset -> int -> tactic
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    60
  val slow_simp_tac: clasimpset -> int -> tactic
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    61
  val best_simp_tac: clasimpset -> int -> tactic
8639
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
    62
  val change_global_css: (clasimpset * thm list -> clasimpset) -> theory attribute
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
    63
  val change_local_css: (clasimpset * thm list -> clasimpset) -> Proof.context attribute
9506
e5857656b8f0 export get_local_clasimpset, clasimp_modifiers;
wenzelm
parents: 9440
diff changeset
    64
  val get_local_clasimpset: Proof.context -> clasimpset
9860
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    65
  val iff_add_global: theory attribute
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    66
  val iff_del_global: theory attribute
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    67
  val iff_add_local: Proof.context attribute
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    68
  val iff_del_local: Proof.context attribute
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    69
  val iff_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list
9506
e5857656b8f0 export get_local_clasimpset, clasimp_modifiers;
wenzelm
parents: 9440
diff changeset
    70
  val clasimp_modifiers: (Args.T list -> (Method.modifier * Args.T list)) list
9860
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
    71
  val setup: (theory -> theory) list
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    72
end;
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    73
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    74
functor ClasimpFun(Data: CLASIMP_DATA): CLASIMP =
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    75
struct
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    76
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    77
open Data;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    78
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    79
type claset = Classical.claset;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    80
type simpset = Simplifier.simpset;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    81
type clasimpset = claset * simpset;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    82
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    83
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    84
(* clasimpset operations *)
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    85
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    86
(*this interface for updating a clasimpset is rudimentary and just for
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    87
  convenience for the most common cases*)
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    88
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    89
fun pair_upd1 f ((a,b),x) = (f(a,x), b);
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    90
fun pair_upd2 f ((a,b),x) = (a, f(b,x));
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    91
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    92
fun op addSIs2   arg = pair_upd1 Classical.addSIs arg;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    93
fun op addSEs2   arg = pair_upd1 Classical.addSEs arg;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    94
fun op addSDs2   arg = pair_upd1 Classical.addSDs arg;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    95
fun op addIs2    arg = pair_upd1 Classical.addIs arg;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    96
fun op addEs2    arg = pair_upd1 Classical.addEs arg;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    97
fun op addDs2    arg = pair_upd1 Classical.addDs arg;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    98
fun op addsimps2 arg = pair_upd2 Simplifier.addsimps arg;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    99
fun op delsimps2 arg = pair_upd2 Simplifier.delsimps arg;
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   100
9402
480a1b40fdd6 strengthened force_tac by using new first_best_tac
oheimb
parents: 8639
diff changeset
   101
(*not totally safe: may instantiate unknowns that appear also in other subgoals*)
480a1b40fdd6 strengthened force_tac by using new first_best_tac
oheimb
parents: 8639
diff changeset
   102
val safe_asm_full_simp_tac = Simplifier.generic_simp_tac true (true,true,true);
480a1b40fdd6 strengthened force_tac by using new first_best_tac
oheimb
parents: 8639
diff changeset
   103
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   104
(*Add a simpset to a classical set!*)
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   105
(*Caution: only one simpset added can be added by each of addSss and addss*)
5567
99c6ef61288f deleted illegal "op"
paulson
parents: 5554
diff changeset
   106
fun cs addSss ss = Classical.addSaltern (cs, ("safe_asm_full_simp_tac",
9772
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   107
                            CHANGED o safe_asm_full_simp_tac ss));
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   108
fun cs addss  ss = Classical.addbefore  (cs, ("asm_full_simp_tac",
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   109
                            CHANGED o Simplifier.asm_full_simp_tac ss));
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   110
9860
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   111
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   112
(* iffs: addition of rules to simpsets and clasets simultaneously *)
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   113
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   114
(*Takes UNCONDITIONAL theorems of the form A<->B to
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   115
        the Safe Intr     rule B==>A and
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   116
        the Safe Destruct rule A==>B.
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   117
  Also ~A goes to the Safe Elim rule A ==> ?R
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   118
  Failing other cases, A is added as a Safe Intr rule*)
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   119
local
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   120
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   121
fun addIff ((cla, simp), th) =
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   122
  (case dest_Trueprop (#prop (rep_thm th)) of
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   123
    con $ _ $ _ =>
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   124
      if con = Data.iff_const then
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   125
        Classical.addSDs (Classical.addSIs (cla, [zero_var_indexes (th RS Data.iffD2)]),
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   126
          [zero_var_indexes (th RS Data.iffD1)])
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   127
      else Classical.addSIs (cla, [th])
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   128
  | con $ A =>
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   129
      if con = Data.not_const then Classical.addSEs (cla, [zero_var_indexes (th RS Data.notE)])
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   130
      else Classical.addSIs (cla, [th])
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   131
  | _ => Classical.addSIs (cla, [th]), Simplifier.addsimps (simp, [th]))
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   132
  handle TERM _ => error ("iff add: theorem must be unconditional\n" ^ Display.string_of_thm th);
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   133
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   134
fun delIff ((cla, simp), th) =
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   135
  (case dest_Trueprop (#prop (rep_thm th)) of
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   136
    con $ _ $ _ =>
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   137
      if con = Data.iff_const then
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   138
        Classical.delrules (cla, [zero_var_indexes (th RS Data.iffD2),
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   139
          Data.cla_make_elim (zero_var_indexes (th RS Data.iffD1))])
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   140
      else Classical.delrules (cla, [th])
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   141
  | con $ A =>
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   142
      if con = Data.not_const then Classical.delrules (cla, [zero_var_indexes (th RS Data.notE)])
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   143
      else Classical.delrules (cla, [th])
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   144
  | _ => Classical.delrules (cla, [th]), Simplifier.delsimps (simp, [th]))
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   145
  handle TERM _ =>
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   146
    (warning ("iff del: ignoring conditional theorem\n" ^ string_of_thm th); (cla, simp));
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   147
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   148
fun store_clasimp (cla, simp) =
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   149
  (Classical.claset_ref () := cla; Simplifier.simpset_ref () := simp);
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   150
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   151
in
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   152
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   153
val op addIffs = foldl addIff;
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   154
val op delIffs = foldl delIff;
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   155
fun AddIffs thms = store_clasimp ((Classical.claset (), Simplifier.simpset ()) addIffs thms);
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   156
fun DelIffs thms = store_clasimp ((Classical.claset (), Simplifier.simpset ()) delIffs thms);
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   157
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   158
end;
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   159
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   160
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   161
(* tacticals *)
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   162
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   163
fun CLASIMPSET tacf state =
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   164
  Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss))) state;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   165
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   166
fun CLASIMPSET' tacf i state =
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   167
  Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss) i)) state;
4888
7301ff9f412b added CLASIMPSET(') tacticals;
wenzelm
parents: 4884
diff changeset
   168
7301ff9f412b added CLASIMPSET(') tacticals;
wenzelm
parents: 4884
diff changeset
   169
9402
480a1b40fdd6 strengthened force_tac by using new first_best_tac
oheimb
parents: 8639
diff changeset
   170
fun clarsimp_tac (cs, ss) = safe_asm_full_simp_tac ss THEN_ALL_NEW
9772
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   171
                            Classical.clarify_tac (cs addSss ss);
5483
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
   172
fun Clarsimp_tac i = clarsimp_tac (Classical.claset(), Simplifier.simpset()) i;
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
   173
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
   174
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   175
(* auto_tac *)
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   176
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   177
fun blast_depth_tac cs m i thm =
9772
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   178
    Blast.depth_tac cs m i thm
5554
3cae5d6510c2 removed addcongs2 and delcongs2
oheimb
parents: 5525
diff changeset
   179
      handle Blast.TRANS s => (warning ("Blast_tac: " ^ s); Seq.empty);
9772
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   180
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   181
(* a variant of depth_tac that avoids interference of the simplifier
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   182
   with dup_step_tac when they are combined by auto_tac *)
5756
8ef5288c24b0 corrected auto_tac (applications of unsafe wrappers)
oheimb
parents: 5567
diff changeset
   183
local
9772
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   184
fun slow_step_tac' cs = Classical.appWrappers cs
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   185
        (Classical.instp_step_tac cs APPEND' Classical.haz_step_tac cs);
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   186
in fun nodup_depth_tac cs m i state = SELECT_GOAL
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   187
   (Classical.safe_steps_tac cs 1 THEN_ELSE
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   188
        (DEPTH_SOLVE (nodup_depth_tac cs m 1),
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   189
         Classical.inst0_step_tac cs 1 APPEND COND (K (m=0)) no_tac
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   190
             (slow_step_tac' cs 1 THEN DEPTH_SOLVE (nodup_depth_tac cs (m-1) 1))
5756
8ef5288c24b0 corrected auto_tac (applications of unsafe wrappers)
oheimb
parents: 5567
diff changeset
   191
        )) i state;
8ef5288c24b0 corrected auto_tac (applications of unsafe wrappers)
oheimb
parents: 5567
diff changeset
   192
end;
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   193
9402
480a1b40fdd6 strengthened force_tac by using new first_best_tac
oheimb
parents: 8639
diff changeset
   194
(*Designed to be idempotent, except if blast_depth_tac instantiates variables
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   195
  in some of the subgoals*)
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   196
fun mk_auto_tac (cs, ss) m n =
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   197
    let val cs' = cs addss ss
9772
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   198
        val maintac =
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   199
          blast_depth_tac cs m               (* fast but can't use wrappers *)
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   200
          ORELSE'
5756
8ef5288c24b0 corrected auto_tac (applications of unsafe wrappers)
oheimb
parents: 5567
diff changeset
   201
          (CHANGED o nodup_depth_tac cs' n); (* slower but more general *)
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   202
    in  EVERY [ALLGOALS (Simplifier.asm_full_simp_tac ss),
9772
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   203
               TRY (Classical.safe_tac cs),
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   204
               REPEAT (FIRSTGOAL maintac),
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   205
               TRY (Classical.safe_tac (cs addSss ss)),
9772
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   206
               prune_params_tac]
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   207
    end;
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   208
9772
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   209
fun auto_tac css = mk_auto_tac css 4 2;
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   210
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   211
fun Auto_tac st = auto_tac (Classical.claset(), Simplifier.simpset()) st;
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   212
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   213
fun auto () = by Auto_tac;
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   214
9772
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   215
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   216
(* force_tac *)
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   217
4659
a78ecc7341e3 added smart_tac
oheimb
parents: 4652
diff changeset
   218
(* aimed to solve the given subgoal totally, using whatever tools possible *)
4717
1370ad043564 renamed smart_tac to force_tac, slight improvement of force_tac
oheimb
parents: 4659
diff changeset
   219
fun force_tac (cs,ss) = let val cs' = cs addss ss in SELECT_GOAL (EVERY [
9772
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   220
        Classical.clarify_tac cs' 1,
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   221
        IF_UNSOLVED (Simplifier.asm_full_simp_tac ss 1),
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   222
        ALLGOALS (Classical.first_best_tac cs')]) end;
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   223
fun Force_tac i = force_tac (Classical.claset(), Simplifier.simpset()) i;
4717
1370ad043564 renamed smart_tac to force_tac, slight improvement of force_tac
oheimb
parents: 4659
diff changeset
   224
fun force i = by (Force_tac i);
4659
a78ecc7341e3 added smart_tac
oheimb
parents: 4652
diff changeset
   225
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   226
9805
10b617bdd028 added "slowsimp", "bestsimp";
wenzelm
parents: 9772
diff changeset
   227
(* basic combinations *)
10b617bdd028 added "slowsimp", "bestsimp";
wenzelm
parents: 9772
diff changeset
   228
10b617bdd028 added "slowsimp", "bestsimp";
wenzelm
parents: 9772
diff changeset
   229
fun ADDSS tac (cs, ss) = let val cs' = cs addss ss in tac cs' end;
9591
590d36e059d1 added "fastsimp";
wenzelm
parents: 9506
diff changeset
   230
9805
10b617bdd028 added "slowsimp", "bestsimp";
wenzelm
parents: 9772
diff changeset
   231
val fast_simp_tac = ADDSS Classical.fast_tac;
10b617bdd028 added "slowsimp", "bestsimp";
wenzelm
parents: 9772
diff changeset
   232
val slow_simp_tac = ADDSS Classical.slow_tac;
10b617bdd028 added "slowsimp", "bestsimp";
wenzelm
parents: 9772
diff changeset
   233
val best_simp_tac = ADDSS Classical.best_tac;
9591
590d36e059d1 added "fastsimp";
wenzelm
parents: 9506
diff changeset
   234
590d36e059d1 added "fastsimp";
wenzelm
parents: 9506
diff changeset
   235
9860
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   236
(* access clasimpset *)
8639
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   237
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   238
fun change_global_css f (thy, th) =
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   239
  let
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   240
    val cs_ref = Classical.claset_ref_of thy;
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   241
    val ss_ref = Simplifier.simpset_ref_of thy;
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   242
    val (cs', ss') = f ((! cs_ref, ! ss_ref), [th]);
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   243
  in cs_ref := cs'; ss_ref := ss'; (thy, th) end;
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   244
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   245
fun change_local_css f (ctxt, th) =
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   246
  let
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   247
    val cs = Classical.get_local_claset ctxt;
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   248
    val ss = Simplifier.get_local_simpset ctxt;
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   249
    val (cs', ss') = f ((cs, ss), [th]);
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   250
    val ctxt' =
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   251
      ctxt
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   252
      |> Classical.put_local_claset cs'
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   253
      |> Simplifier.put_local_simpset ss';
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   254
  in (ctxt', th) end;
31bcb6b64d60 added change_global/local_css;
wenzelm
parents: 8469
diff changeset
   255
7153
wenzelm
parents: 7132
diff changeset
   256
fun get_local_clasimpset ctxt =
wenzelm
parents: 7132
diff changeset
   257
  (Classical.get_local_claset ctxt, Simplifier.get_local_simpset ctxt);
5926
58f9ca06b76b method setup;
wenzelm
parents: 5756
diff changeset
   258
9860
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   259
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   260
(* attributes *)
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   261
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   262
val iff_add_global = change_global_css (op addIffs);
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   263
val iff_del_global = change_global_css (op delIffs);
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   264
val iff_add_local = change_local_css (op addIffs);
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   265
val iff_del_local = change_local_css (op delIffs);
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   266
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   267
val iff_attr =
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   268
 (Attrib.add_del_args iff_add_global iff_del_global,
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   269
  Attrib.add_del_args iff_add_local iff_del_local);
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   270
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   271
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   272
(* method modifiers *)
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   273
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   274
val iffN = "iff";
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   275
val addN = "add";
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   276
val delN = "del";
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   277
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   278
val iff_modifiers =
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   279
 [Args.$$$ iffN -- Args.colon >> K ((I, iff_add_local): Method.modifier),
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   280
  Args.$$$ iffN -- Args.$$$ addN -- Args.colon >> K (I, iff_add_local),
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   281
  Args.$$$ iffN -- Args.$$$ delN -- Args.colon >> K (I, iff_del_local)];
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   282
8469
482c301041b4 include Splitter.split_modifiers;
wenzelm
parents: 8168
diff changeset
   283
val clasimp_modifiers =
9860
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   284
  Simplifier.simp_modifiers @ Splitter.split_modifiers @
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   285
  Classical.cla_modifiers @ iff_modifiers;
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   286
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   287
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   288
(* methods *)
5926
58f9ca06b76b method setup;
wenzelm
parents: 5756
diff changeset
   289
7559
1d2c099e98f7 setup for refined facts handling;
wenzelm
parents: 7437
diff changeset
   290
fun clasimp_meth tac prems ctxt = Method.METHOD (fn facts =>
1d2c099e98f7 setup for refined facts handling;
wenzelm
parents: 7437
diff changeset
   291
  ALLGOALS (Method.insert_tac (prems @ facts)) THEN tac (get_local_clasimpset ctxt));
7132
5c31d06ead04 eliminated METHOD0 in favour of same_tac;
wenzelm
parents: 5985
diff changeset
   292
7559
1d2c099e98f7 setup for refined facts handling;
wenzelm
parents: 7437
diff changeset
   293
fun clasimp_meth' tac prems ctxt = Method.METHOD (fn facts =>
8168
9d2ac5439089 HEADGOAL;
wenzelm
parents: 8154
diff changeset
   294
  HEADGOAL (Method.insert_tac (prems @ facts) THEN' tac (get_local_clasimpset ctxt)));
5926
58f9ca06b76b method setup;
wenzelm
parents: 5756
diff changeset
   295
7559
1d2c099e98f7 setup for refined facts handling;
wenzelm
parents: 7437
diff changeset
   296
val clasimp_method = Method.bang_sectioned_args clasimp_modifiers o clasimp_meth;
1d2c099e98f7 setup for refined facts handling;
wenzelm
parents: 7437
diff changeset
   297
val clasimp_method' = Method.bang_sectioned_args clasimp_modifiers o clasimp_meth';
5926
58f9ca06b76b method setup;
wenzelm
parents: 5756
diff changeset
   298
58f9ca06b76b method setup;
wenzelm
parents: 5756
diff changeset
   299
9772
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   300
fun auto_args m =
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   301
  Method.bang_sectioned_args' clasimp_modifiers (Scan.lift (Scan.option (Args.nat -- Args.nat))) m;
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   302
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   303
fun auto_meth None = clasimp_meth (CHANGED o auto_tac)
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   304
  | auto_meth (Some (m, n)) = clasimp_meth (CHANGED o (fn css => mk_auto_tac css m n));
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   305
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   306
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   307
(* theory setup *)
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   308
5926
58f9ca06b76b method setup;
wenzelm
parents: 5756
diff changeset
   309
val setup =
9860
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   310
 [Attrib.add_attributes
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   311
  [("iff", iff_attr, "declare simplifier / classical rules")],
5c5efed691b9 added 'iff' declarations;
wenzelm
parents: 9805
diff changeset
   312
  Method.add_methods
9591
590d36e059d1 added "fastsimp";
wenzelm
parents: 9506
diff changeset
   313
   [("fastsimp", clasimp_method' fast_simp_tac, "combined fast and simp"),
9805
10b617bdd028 added "slowsimp", "bestsimp";
wenzelm
parents: 9772
diff changeset
   314
    ("slowsimp", clasimp_method' slow_simp_tac, "combined slow and simp"),
10b617bdd028 added "slowsimp", "bestsimp";
wenzelm
parents: 9772
diff changeset
   315
    ("bestsimp", clasimp_method' best_simp_tac, "combined best and simp"),
9591
590d36e059d1 added "fastsimp";
wenzelm
parents: 9506
diff changeset
   316
    ("force", clasimp_method' force_tac, "force"),
9772
c07777210a69 auto method: opt args;
wenzelm
parents: 9591
diff changeset
   317
    ("auto", auto_args auto_meth, "auto"),
9591
590d36e059d1 added "fastsimp";
wenzelm
parents: 9506
diff changeset
   318
    ("clarsimp", clasimp_method' (CHANGED oo clarsimp_tac), "clarify simplified goal")]];
5926
58f9ca06b76b method setup;
wenzelm
parents: 5756
diff changeset
   319
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   320
end;