1 (* Title: Provers/clasimp.ML |
1 (* Title: Provers/clasimp.ML |
2 ID: $Id$ |
2 ID: $Id$ |
3 Author: David von Oheimb, TU Muenchen |
3 Author: David von Oheimb, TU Muenchen |
4 |
4 |
5 Combination of classical reasoner and simplifier |
5 Combination of classical reasoner and simplifier (depends on |
6 to be used after installing both of them |
6 simplifier.ML, classical.ML, blast.ML). |
7 *) |
7 *) |
8 |
|
9 type clasimpset = claset * simpset; |
|
10 |
8 |
11 infix 4 addSIs2 addSEs2 addSDs2 addIs2 addEs2 addDs2 |
9 infix 4 addSIs2 addSEs2 addSDs2 addIs2 addEs2 addDs2 |
12 addsimps2 delsimps2 addcongs2 delcongs2; |
10 addsimps2 delsimps2 addcongs2 delcongs2; |
13 infix 4 addSss addss; |
11 infix 4 addSss addss; |
14 |
12 |
|
13 signature CLASIMP_DATA = |
|
14 sig |
|
15 structure Simplifier: SIMPLIFIER |
|
16 structure Classical: CLASSICAL |
|
17 structure Blast: BLAST |
|
18 sharing type Classical.claset = Blast.claset |
|
19 val addcongs: Simplifier.simpset * thm list -> Simplifier.simpset |
|
20 val delcongs: Simplifier.simpset * thm list -> Simplifier.simpset |
|
21 val addSaltern: Classical.claset * (string * (int -> tactic)) -> Classical.claset |
|
22 val addbefore: Classical.claset * (string * (int -> tactic)) -> Classical.claset |
|
23 end |
|
24 |
15 signature CLASIMP = |
25 signature CLASIMP = |
16 sig |
26 sig |
|
27 include CLASIMP_DATA |
|
28 type claset |
|
29 type simpset |
|
30 type clasimpset |
17 val addSIs2 : clasimpset * thm list -> clasimpset |
31 val addSIs2 : clasimpset * thm list -> clasimpset |
18 val addSEs2 : clasimpset * thm list -> clasimpset |
32 val addSEs2 : clasimpset * thm list -> clasimpset |
19 val addSDs2 : clasimpset * thm list -> clasimpset |
33 val addSDs2 : clasimpset * thm list -> clasimpset |
20 val addIs2 : clasimpset * thm list -> clasimpset |
34 val addIs2 : clasimpset * thm list -> clasimpset |
21 val addEs2 : clasimpset * thm list -> clasimpset |
35 val addEs2 : clasimpset * thm list -> clasimpset |
33 val force_tac : clasimpset -> int -> tactic |
47 val force_tac : clasimpset -> int -> tactic |
34 val Force_tac : int -> tactic |
48 val Force_tac : int -> tactic |
35 val force : int -> unit |
49 val force : int -> unit |
36 end; |
50 end; |
37 |
51 |
38 structure Clasimp: CLASIMP = |
52 functor ClasimpFun(Data: CLASIMP_DATA): CLASIMP = |
39 struct |
53 struct |
40 |
54 |
41 (* this interface for updating a clasimpset is rudimentary and just for |
55 open Data; |
42 convenience for the most common cases. |
56 |
43 In other cases a clasimpset may be dealt with componentwise. *) |
57 type claset = Classical.claset; |
44 local |
58 type simpset = Simplifier.simpset; |
45 fun pair_upd1 f ((a,b),x) = (f(a,x), b); |
59 type clasimpset = claset * simpset; |
46 fun pair_upd2 f ((a,b),x) = (a, f(b,x)); |
60 |
47 in |
61 |
48 fun op addSIs2 arg = pair_upd1 (op addSIs) arg; |
62 (* clasimpset operations *) |
49 fun op addSEs2 arg = pair_upd1 (op addSEs) arg; |
63 |
50 fun op addSDs2 arg = pair_upd1 (op addSDs) arg; |
64 (*this interface for updating a clasimpset is rudimentary and just for |
51 fun op addIs2 arg = pair_upd1 (op addIs ) arg; |
65 convenience for the most common cases*) |
52 fun op addEs2 arg = pair_upd1 (op addEs ) arg; |
66 |
53 fun op addDs2 arg = pair_upd1 (op addDs ) arg; |
67 fun pair_upd1 f ((a,b),x) = (f(a,x), b); |
54 fun op addsimps2 arg = pair_upd2 (op addsimps) arg; |
68 fun pair_upd2 f ((a,b),x) = (a, f(b,x)); |
55 fun op delsimps2 arg = pair_upd2 (op delsimps) arg; |
69 |
56 fun op addcongs2 arg = pair_upd2 (op addcongs) arg; |
70 fun op addSIs2 arg = pair_upd1 Classical.addSIs arg; |
57 fun op delcongs2 arg = pair_upd2 (op delcongs) arg; |
71 fun op addSEs2 arg = pair_upd1 Classical.addSEs arg; |
58 end; |
72 fun op addSDs2 arg = pair_upd1 Classical.addSDs arg; |
|
73 fun op addIs2 arg = pair_upd1 Classical.addIs arg; |
|
74 fun op addEs2 arg = pair_upd1 Classical.addEs arg; |
|
75 fun op addDs2 arg = pair_upd1 Classical.addDs arg; |
|
76 fun op addsimps2 arg = pair_upd2 Simplifier.addsimps arg; |
|
77 fun op delsimps2 arg = pair_upd2 Simplifier.delsimps arg; |
|
78 fun op addcongs2 arg = pair_upd2 Data.addcongs arg; |
|
79 fun op delcongs2 arg = pair_upd2 Data.delcongs arg; |
59 |
80 |
60 (*Add a simpset to a classical set!*) |
81 (*Add a simpset to a classical set!*) |
61 (*Caution: only one simpset added can be added by each of addSss and addss*) |
82 (*Caution: only one simpset added can be added by each of addSss and addss*) |
62 fun cs addSss ss = cs addSaltern ("safe_asm_full_simp_tac", |
83 fun cs addSss ss = cs addSaltern ("safe_asm_full_simp_tac", |
63 CHANGED o (safe_asm_full_simp_tac ss)); |
84 CHANGED o Simplifier.safe_asm_full_simp_tac ss); |
64 fun cs addss ss = cs addbefore ( "asm_full_simp_tac", |
85 fun cs addss ss = cs addbefore ("asm_full_simp_tac", Simplifier.asm_full_simp_tac ss); |
65 asm_full_simp_tac ss); |
|
66 |
86 |
67 |
87 |
68 fun CLASIMPSET tacf state = CLASET (fn cs => SIMPSET (fn ss => tacf (cs, ss))) state; |
88 (* tacticals *) |
69 fun CLASIMPSET' tacf i state = CLASET (fn cs => SIMPSET (fn ss => tacf (cs, ss) i)) state; |
89 |
|
90 fun CLASIMPSET tacf state = |
|
91 Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss))) state; |
|
92 |
|
93 fun CLASIMPSET' tacf i state = |
|
94 Classical.CLASET (fn cs => Simplifier.SIMPSET (fn ss => tacf (cs, ss) i)) state; |
70 |
95 |
71 |
96 |
72 local |
97 (* auto_tac *) |
73 |
98 |
74 fun blast_depth_tac cs m i thm = Blast.depth_tac cs m i thm |
99 fun blast_depth_tac cs m i thm = |
75 handle Blast.TRANS s => (warning ("Blast_tac: " ^ s); Seq.empty); |
100 Blast.depth_tac cs m i thm handle Blast.TRANS s => (warning ("Blast_tac: " ^ s); Seq.empty); |
76 |
101 |
77 (* a variant of depth_tac that avoids interference of the simplifier |
102 (* a variant of depth_tac that avoids interference of the simplifier |
78 with dup_step_tac when they are combined by auto_tac *) |
103 with dup_step_tac when they are combined by auto_tac *) |
79 fun nodup_depth_tac cs m i state = |
104 fun nodup_depth_tac cs m i state = |
80 SELECT_GOAL |
105 SELECT_GOAL |
81 (appWrappers cs |
106 (Classical.appWrappers cs |
82 (fn i => REPEAT_DETERM1 (COND (has_fewer_prems i) no_tac |
107 (fn i => REPEAT_DETERM1 (COND (has_fewer_prems i) no_tac |
83 (safe_step_tac cs i)) THEN_ELSE |
108 (Classical.safe_step_tac cs i)) THEN_ELSE |
84 (DEPTH_SOLVE (nodup_depth_tac cs m i), |
109 (DEPTH_SOLVE (nodup_depth_tac cs m i), |
85 inst0_step_tac cs i APPEND |
110 Classical.inst0_step_tac cs i APPEND |
86 COND (K(m=0)) no_tac |
111 COND (K(m=0)) no_tac |
87 ((instp_step_tac cs i APPEND step_tac cs i) |
112 ((Classical.instp_step_tac cs i APPEND Classical.step_tac cs i) |
88 THEN DEPTH_SOLVE (nodup_depth_tac cs (m-1) i)))) 1) |
113 THEN DEPTH_SOLVE (nodup_depth_tac cs (m-1) i)))) 1) |
89 i state; |
114 i state; |
90 |
|
91 in |
|
92 |
115 |
93 (*Designed to be idempotent, except if best_tac instantiates variables |
116 (*Designed to be idempotent, except if best_tac instantiates variables |
94 in some of the subgoals*) |
117 in some of the subgoals*) |
95 fun mk_auto_tac (cs, ss) m n = |
118 fun mk_auto_tac (cs, ss) m n = |
96 let val cs' = cs addss ss |
119 let val cs' = cs addss ss |
97 val maintac = |
120 val maintac = |
98 blast_depth_tac cs m (*fast but can't use addss*) |
121 blast_depth_tac cs m (*fast but can't use addss*) |
99 ORELSE' |
122 ORELSE' |
100 nodup_depth_tac cs' n; (*slower but more general*) |
123 nodup_depth_tac cs' n; (*slower but more general*) |
101 in EVERY [ALLGOALS (asm_full_simp_tac ss), |
124 in EVERY [ALLGOALS (Simplifier.asm_full_simp_tac ss), |
102 TRY (safe_tac cs'), |
125 TRY (Classical.safe_tac cs'), |
103 REPEAT (FIRSTGOAL maintac), |
126 REPEAT (FIRSTGOAL maintac), |
104 TRY (safe_tac (cs addSss ss)), |
127 TRY (Classical.safe_tac (cs addSss ss)), |
105 prune_params_tac] |
128 prune_params_tac] |
106 end; |
129 end; |
107 end; |
|
108 |
130 |
109 fun auto_tac (cs,ss) = mk_auto_tac (cs,ss) 4 2; |
131 fun auto_tac (cs,ss) = mk_auto_tac (cs,ss) 4 2; |
110 |
132 |
111 fun Auto_tac st = auto_tac (claset(), simpset()) st; |
133 fun Auto_tac st = auto_tac (Classical.claset(), Simplifier.simpset()) st; |
112 |
134 |
113 fun auto () = by Auto_tac; |
135 fun auto () = by Auto_tac; |
114 |
136 |
|
137 |
|
138 (* force_tac *) |
|
139 |
115 (* aimed to solve the given subgoal totally, using whatever tools possible *) |
140 (* aimed to solve the given subgoal totally, using whatever tools possible *) |
116 fun force_tac (cs,ss) = let val cs' = cs addss ss in SELECT_GOAL (EVERY [ |
141 fun force_tac (cs,ss) = let val cs' = cs addss ss in SELECT_GOAL (EVERY [ |
117 clarify_tac cs' 1, |
142 Classical.clarify_tac cs' 1, |
118 IF_UNSOLVED (asm_full_simp_tac ss 1), |
143 IF_UNSOLVED (Simplifier.asm_full_simp_tac ss 1), |
119 ALLGOALS (best_tac cs')]) end; |
144 ALLGOALS (Classical.best_tac cs')]) end; |
120 fun Force_tac i = force_tac (claset(), simpset()) i; |
145 fun Force_tac i = force_tac (Classical.claset(), Simplifier.simpset()) i; |
121 fun force i = by (Force_tac i); |
146 fun force i = by (Force_tac i); |
122 |
147 |
|
148 |
123 end; |
149 end; |