1 (* Title: Provers/clasimp.ML
3 Author: David von Oheimb, TU Muenchen
5 Combination of classical reasoner and simplifier (depends on
6 simplifier.ML, classical.ML, blast.ML).
9 infix 4 addSIs2 addSEs2 addSDs2 addIs2 addEs2 addDs2 addsimps2 delsimps2;
12 signature CLASIMP_DATA =
14 structure Simplifier: SIMPLIFIER
15 structure Classical: CLASSICAL
16 structure Blast: BLAST
17 sharing type Classical.claset = Blast.claset
26 val addSIs2 : clasimpset * thm list -> clasimpset
27 val addSEs2 : clasimpset * thm list -> clasimpset
28 val addSDs2 : clasimpset * thm list -> clasimpset
29 val addIs2 : clasimpset * thm list -> clasimpset
30 val addEs2 : clasimpset * thm list -> clasimpset
31 val addDs2 : clasimpset * thm list -> clasimpset
32 val addsimps2 : clasimpset * thm list -> clasimpset
33 val delsimps2 : clasimpset * thm list -> clasimpset
34 val addSss : claset * simpset -> claset
35 val addss : claset * simpset -> claset
36 val CLASIMPSET :(clasimpset -> tactic) -> tactic
37 val CLASIMPSET' :(clasimpset -> 'a -> tactic) -> 'a -> tactic
38 val clarsimp_tac: clasimpset -> int -> tactic
39 val Clarsimp_tac: int -> tactic
40 val mk_auto_tac : clasimpset -> int -> int -> tactic
41 val auto_tac : clasimpset -> tactic
43 val auto : unit -> unit
44 val force_tac : clasimpset -> int -> tactic
45 val Force_tac : int -> tactic
46 val force : int -> unit
47 val setup : (theory -> theory) list
50 functor ClasimpFun(Data: CLASIMP_DATA): CLASIMP =
55 type claset = Classical.claset;
56 type simpset = Simplifier.simpset;
57 type clasimpset = claset * simpset;
60 (* clasimpset operations *)
62 (*this interface for updating a clasimpset is rudimentary and just for
63 convenience for the most common cases*)
65 fun pair_upd1 f ((a,b),x) = (f(a,x), b);
66 fun pair_upd2 f ((a,b),x) = (a, f(b,x));
68 fun op addSIs2 arg = pair_upd1 Classical.addSIs arg;
69 fun op addSEs2 arg = pair_upd1 Classical.addSEs arg;
70 fun op addSDs2 arg = pair_upd1 Classical.addSDs arg;
71 fun op addIs2 arg = pair_upd1 Classical.addIs arg;
72 fun op addEs2 arg = pair_upd1 Classical.addEs arg;
73 fun op addDs2 arg = pair_upd1 Classical.addDs arg;
74 fun op addsimps2 arg = pair_upd2 Simplifier.addsimps arg;
75 fun op delsimps2 arg = pair_upd2 Simplifier.delsimps arg;
77 (*Add a simpset to a classical set!*)
78 (*Caution: only one simpset added can be added by each of addSss and addss*)
79 fun cs addSss ss = Classical.addSaltern (cs, ("safe_asm_full_simp_tac",
80 CHANGED o Simplifier.safe_asm_full_simp_tac ss));
81 fun cs addss ss = Classical.addbefore (cs, ("asm_full_simp_tac",
82 CHANGED o Simplifier.asm_full_simp_tac ss));
86 fun CLASIMPSET tacf state =
87 Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss))) state;
89 fun CLASIMPSET' tacf i state =
90 Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss) i)) state;
93 fun clarsimp_tac (cs, ss) = Simplifier.safe_asm_full_simp_tac ss THEN_MAYBE'
94 Classical.clarify_tac (cs addSss ss);
95 fun Clarsimp_tac i = clarsimp_tac (Classical.claset(), Simplifier.simpset()) i;
100 fun blast_depth_tac cs m i thm =
101 Blast.depth_tac cs m i thm
102 handle Blast.TRANS s => (warning ("Blast_tac: " ^ s); Seq.empty);
104 (* a variant of depth_tac that avoids interference of the simplifier
105 with dup_step_tac when they are combined by auto_tac *)
107 fun slow_step_tac' cs = Classical.appWrappers cs
108 (Classical.instp_step_tac cs APPEND' Classical.haz_step_tac cs);
109 in fun nodup_depth_tac cs m i state = SELECT_GOAL
110 (Classical.safe_steps_tac cs 1 THEN_ELSE
111 (DEPTH_SOLVE (nodup_depth_tac cs m 1),
112 Classical.inst0_step_tac cs 1 APPEND COND (K (m=0)) no_tac
113 (slow_step_tac' cs 1 THEN DEPTH_SOLVE (nodup_depth_tac cs (m-1) 1))
117 (*Designed to be idempotent, except if best_tac instantiates variables
118 in some of the subgoals*)
119 fun mk_auto_tac (cs, ss) m n =
120 let val cs' = cs addss ss
122 blast_depth_tac cs m (* fast but can't use wrappers *)
124 (CHANGED o nodup_depth_tac cs' n); (* slower but more general *)
125 in EVERY [ALLGOALS (Simplifier.asm_full_simp_tac ss),
126 TRY (Classical.safe_tac cs),
127 REPEAT (FIRSTGOAL maintac),
128 TRY (Classical.safe_tac (cs addSss ss)),
132 fun auto_tac (cs,ss) = mk_auto_tac (cs,ss) 4 2;
134 fun Auto_tac st = auto_tac (Classical.claset(), Simplifier.simpset()) st;
136 fun auto () = by Auto_tac;
141 (* aimed to solve the given subgoal totally, using whatever tools possible *)
142 fun force_tac (cs,ss) = let val cs' = cs addss ss in SELECT_GOAL (EVERY [
143 Classical.clarify_tac cs' 1,
144 IF_UNSOLVED (Simplifier.asm_full_simp_tac ss 1),
145 ALLGOALS (Classical.best_tac cs')]) end;
146 fun Force_tac i = force_tac (Classical.claset(), Simplifier.simpset()) i;
147 fun force i = by (Force_tac i);
152 fun get_local_clasimpset ctxt =
153 (Classical.get_local_claset ctxt, Simplifier.get_local_simpset ctxt);
155 val clasimp_modifiers = Classical.cla_modifiers @ Simplifier.simp_modifiers;
157 fun clasimp_meth tac prems ctxt = Method.METHOD (fn facts =>
158 ALLGOALS (Method.insert_tac (prems @ facts)) THEN tac (get_local_clasimpset ctxt));
160 fun clasimp_meth' tac prems ctxt = Method.METHOD (fn facts =>
161 FIRSTGOAL (Method.insert_tac (prems @ facts) THEN' tac (get_local_clasimpset ctxt)));
163 val clasimp_method = Method.bang_sectioned_args clasimp_modifiers o clasimp_meth;
164 val clasimp_method' = Method.bang_sectioned_args clasimp_modifiers o clasimp_meth';
169 [("clarsimp_tac", clasimp_method' clarsimp_tac, "clarsimp (improper!)"),
170 ("auto", clasimp_method (CHANGED o auto_tac), "auto"),
171 ("force", clasimp_method' force_tac, "force")]];