src/Provers/clasimp.ML
author nipkow
Fri, 09 Oct 1998 14:19:13 +0200
changeset 5633 fb7fa1b154c4
parent 5567 99c6ef61288f
child 5756 8ef5288c24b0
permissions -rw-r--r--
Added a few breaks in error text.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
     1
(*  Title: 	Provers/clasimp.ML
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
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
     6
simplifier.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
5554
3cae5d6510c2 removed addcongs2 and delcongs2
oheimb
parents: 5525
diff changeset
     9
infix 4 addSIs2 addSEs2 addSDs2 addIs2 addEs2 addDs2 addsimps2 delsimps2;
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    10
infix 4 addSss addss;
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
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    15
  structure Classical: CLASSICAL
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    16
  structure Blast: BLAST
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    17
  sharing type Classical.claset = Blast.claset
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    18
end
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    19
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    20
signature CLASIMP =
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    21
sig
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    22
  include CLASIMP_DATA
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    23
  type claset
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    24
  type simpset
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    25
  type clasimpset
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    26
  val addSIs2	: clasimpset * thm list -> clasimpset
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    27
  val addSEs2	: clasimpset * thm list -> clasimpset
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    28
  val addSDs2	: clasimpset * thm list -> clasimpset
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    29
  val addIs2	: clasimpset * thm list -> clasimpset
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    30
  val addEs2	: clasimpset * thm list -> clasimpset
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    31
  val addDs2	: clasimpset * thm list -> clasimpset
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    32
  val addsimps2	: clasimpset * thm list -> clasimpset
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    33
  val delsimps2	: clasimpset * thm list -> clasimpset
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    34
  val addSss	: claset * simpset -> claset
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    35
  val addss	: claset * simpset -> claset
5483
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    36
  val CLASIMPSET  :(clasimpset -> tactic) -> tactic
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    37
  val CLASIMPSET' :(clasimpset -> 'a -> tactic) -> 'a -> tactic
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    38
  val clarsimp_tac: clasimpset -> int -> tactic
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    39
  val Clarsimp_tac:               int -> tactic
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    40
  val mk_auto_tac : clasimpset -> int -> int -> tactic
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    41
  val auto_tac	  : clasimpset -> tactic
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    42
  val Auto_tac	  : tactic
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    43
  val auto	  : unit -> unit
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    44
  val force_tac	  : clasimpset  -> int -> tactic
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    45
  val Force_tac	  : int -> tactic
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    46
  val force	  : int -> unit
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    47
end;
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    48
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    49
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
    50
struct
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    51
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    52
open Data;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    53
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    54
type claset = Classical.claset;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    55
type simpset = Simplifier.simpset;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    56
type clasimpset = claset * simpset;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    57
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    58
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    59
(* clasimpset operations *)
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    60
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    61
(*this interface for updating a clasimpset is rudimentary and just for
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    62
  convenience for the most common cases*)
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    63
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    64
fun pair_upd1 f ((a,b),x) = (f(a,x), b);
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    65
fun pair_upd2 f ((a,b),x) = (a, f(b,x));
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    66
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    67
fun op addSIs2   arg = pair_upd1 Classical.addSIs arg;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    68
fun op addSEs2   arg = pair_upd1 Classical.addSEs arg;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    69
fun op addSDs2   arg = pair_upd1 Classical.addSDs arg;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    70
fun op addIs2    arg = pair_upd1 Classical.addIs arg;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    71
fun op addEs2    arg = pair_upd1 Classical.addEs arg;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    72
fun op addDs2    arg = pair_upd1 Classical.addDs arg;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    73
fun op addsimps2 arg = pair_upd2 Simplifier.addsimps arg;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    74
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
    75
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    76
(*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
    77
(*Caution: only one simpset added can be added by each of addSss and addss*)
5567
99c6ef61288f deleted illegal "op"
paulson
parents: 5554
diff changeset
    78
fun cs addSss ss = Classical.addSaltern (cs, ("safe_asm_full_simp_tac",
5554
3cae5d6510c2 removed addcongs2 and delcongs2
oheimb
parents: 5525
diff changeset
    79
			    CHANGED o Simplifier.safe_asm_full_simp_tac ss));
5567
99c6ef61288f deleted illegal "op"
paulson
parents: 5554
diff changeset
    80
fun cs addss  ss = Classical.addbefore  (cs, ("asm_full_simp_tac", 
5554
3cae5d6510c2 removed addcongs2 and delcongs2
oheimb
parents: 5525
diff changeset
    81
			    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
    82
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    83
(* tacticals *)
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    84
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    85
fun CLASIMPSET tacf state =
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    86
  Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss))) state;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    87
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    88
fun CLASIMPSET' tacf i state =
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    89
  Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss) i)) state;
4888
7301ff9f412b added CLASIMPSET(') tacticals;
wenzelm
parents: 4884
diff changeset
    90
7301ff9f412b added CLASIMPSET(') tacticals;
wenzelm
parents: 4884
diff changeset
    91
5483
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    92
fun clarsimp_tac (cs, ss) = Simplifier.safe_asm_full_simp_tac ss THEN_MAYBE'
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    93
			    Classical.clarify_tac (cs addSss ss);
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    94
fun Clarsimp_tac i = clarsimp_tac (Classical.claset(), Simplifier.simpset()) i;
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    95
2fc3f4450fe8 added clarsimp_tac and Clarsimp_tac
oheimb
parents: 5219
diff changeset
    96
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    97
(* auto_tac *)
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
    98
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
    99
fun blast_depth_tac cs m i thm =
5554
3cae5d6510c2 removed addcongs2 and delcongs2
oheimb
parents: 5525
diff changeset
   100
    Blast.depth_tac cs m i thm 
3cae5d6510c2 removed addcongs2 and delcongs2
oheimb
parents: 5525
diff changeset
   101
      handle Blast.TRANS s => (warning ("Blast_tac: " ^ s); Seq.empty);
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   102
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   103
(* a variant of depth_tac that avoids interference of the simplifier 
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   104
   with dup_step_tac when they are combined by auto_tac *)
5525
896f8234b864 improved addbefore and addSbefore
oheimb
parents: 5483
diff changeset
   105
fun nodup_depth_tac cs m i state = CHANGED (SELECT_GOAL 
896f8234b864 improved addbefore and addSbefore
oheimb
parents: 5483
diff changeset
   106
   (REPEAT_DETERM1 (COND (has_fewer_prems 1) no_tac
896f8234b864 improved addbefore and addSbefore
oheimb
parents: 5483
diff changeset
   107
                                             (Classical.safe_step_tac cs 1))
896f8234b864 improved addbefore and addSbefore
oheimb
parents: 5483
diff changeset
   108
    THEN_ELSE (DEPTH_SOLVE (nodup_depth_tac cs m 1),
896f8234b864 improved addbefore and addSbefore
oheimb
parents: 5483
diff changeset
   109
	Classical.appWrappers cs (fn i => Classical.inst0_step_tac cs i APPEND
896f8234b864 improved addbefore and addSbefore
oheimb
parents: 5483
diff changeset
   110
        COND (K(m=0)) no_tac
896f8234b864 improved addbefore and addSbefore
oheimb
parents: 5483
diff changeset
   111
            ((Classical.instp_step_tac cs i APPEND Classical.step_tac cs i)
896f8234b864 improved addbefore and addSbefore
oheimb
parents: 5483
diff changeset
   112
            THEN DEPTH_SOLVE (nodup_depth_tac cs (m-1) i))) 1))
896f8234b864 improved addbefore and addSbefore
oheimb
parents: 5483
diff changeset
   113
  i) state;
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   114
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   115
(*Designed to be idempotent, except if best_tac instantiates variables
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   116
  in some of the subgoals*)
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   117
fun mk_auto_tac (cs, ss) m n =
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   118
    let val cs' = cs addss ss
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   119
        val maintac = 
5554
3cae5d6510c2 removed addcongs2 and delcongs2
oheimb
parents: 5525
diff changeset
   120
          blast_depth_tac cs m		(* fast but can't use addss *)
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   121
          ORELSE'
5554
3cae5d6510c2 removed addcongs2 and delcongs2
oheimb
parents: 5525
diff changeset
   122
          nodup_depth_tac cs' n;	(* slower but more general *)
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   123
    in  EVERY [ALLGOALS (Simplifier.asm_full_simp_tac ss),
5525
896f8234b864 improved addbefore and addSbefore
oheimb
parents: 5483
diff changeset
   124
	       TRY (Classical.safe_tac cs),
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   125
	       REPEAT (FIRSTGOAL maintac),
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   126
               TRY (Classical.safe_tac (cs addSss ss)),
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   127
	       prune_params_tac] 
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   128
    end;
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   129
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   130
fun auto_tac (cs,ss) = mk_auto_tac (cs,ss) 4 2;
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   131
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   132
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
   133
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   134
fun auto () = by Auto_tac;
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   135
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   136
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   137
(* force_tac *)
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   138
4659
a78ecc7341e3 added smart_tac
oheimb
parents: 4652
diff changeset
   139
(* 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
   140
fun force_tac (cs,ss) = let val cs' = cs addss ss in SELECT_GOAL (EVERY [
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   141
	Classical.clarify_tac cs' 1,
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   142
	IF_UNSOLVED (Simplifier.asm_full_simp_tac ss 1),
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   143
	ALLGOALS (Classical.best_tac cs')]) end;
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   144
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
   145
fun force i = by (Force_tac i);
4659
a78ecc7341e3 added smart_tac
oheimb
parents: 4652
diff changeset
   146
5219
924359415f09 functorized Clasimp module;
wenzelm
parents: 4888
diff changeset
   147
4652
d24cca140eeb factored out common code of HOL/simpdata.ML and FOL/simpdata.ML concerning
oheimb
parents:
diff changeset
   148
end;