author | Cezary Kaliszyk <kaliszyk@in.tum.de> |
Fri, 18 Sep 2009 13:44:06 +0200 | |
changeset 20 | ccc220a23887 |
parent 19 | 55aefc2d524a |
child 21 | d15121412caa |
permissions | -rw-r--r-- |
0 | 1 |
theory QuotMain |
6 | 2 |
imports QuotScript QuotList Prove |
0 | 3 |
begin |
4 |
||
5 |
locale QUOT_TYPE = |
|
6 |
fixes R :: "'a \<Rightarrow> 'a \<Rightarrow> bool" |
|
7 |
and Abs :: "('a \<Rightarrow> bool) \<Rightarrow> 'b" |
|
8 |
and Rep :: "'b \<Rightarrow> ('a \<Rightarrow> bool)" |
|
9 |
assumes equiv: "EQUIV R" |
|
10 |
and rep_prop: "\<And>y. \<exists>x. Rep y = R x" |
|
11 |
and rep_inverse: "\<And>x. Abs (Rep x) = x" |
|
12 |
and abs_inverse: "\<And>x. (Rep (Abs (R x))) = (R x)" |
|
13 |
and rep_inject: "\<And>x y. (Rep x = Rep y) = (x = y)" |
|
15 | 14 |
begin |
0 | 15 |
|
16 |
definition |
|
17 |
"ABS x \<equiv> Abs (R x)" |
|
18 |
||
19 |
definition |
|
20 |
"REP a = Eps (Rep a)" |
|
21 |
||
15 | 22 |
lemma lem9: |
0 | 23 |
shows "R (Eps (R x)) = R x" |
24 |
proof - |
|
25 |
have a: "R x x" using equiv by (simp add: EQUIV_REFL_SYM_TRANS REFL_def) |
|
26 |
then have "R x (Eps (R x))" by (rule someI) |
|
15 | 27 |
then show "R (Eps (R x)) = R x" |
0 | 28 |
using equiv unfolding EQUIV_def by simp |
29 |
qed |
|
30 |
||
31 |
theorem thm10: |
|
32 |
shows "ABS (REP a) = a" |
|
33 |
unfolding ABS_def REP_def |
|
34 |
proof - |
|
15 | 35 |
from rep_prop |
0 | 36 |
obtain x where eq: "Rep a = R x" by auto |
37 |
have "Abs (R (Eps (Rep a))) = Abs (R (Eps (R x)))" using eq by simp |
|
38 |
also have "\<dots> = Abs (R x)" using lem9 by simp |
|
39 |
also have "\<dots> = Abs (Rep a)" using eq by simp |
|
40 |
also have "\<dots> = a" using rep_inverse by simp |
|
41 |
finally |
|
42 |
show "Abs (R (Eps (Rep a))) = a" by simp |
|
43 |
qed |
|
44 |
||
15 | 45 |
lemma REP_refl: |
0 | 46 |
shows "R (REP a) (REP a)" |
47 |
unfolding REP_def |
|
48 |
by (simp add: equiv[simplified EQUIV_def]) |
|
49 |
||
50 |
lemma lem7: |
|
51 |
"(R x = R y) = (Abs (R x) = Abs (R y))" |
|
52 |
apply(rule iffI) |
|
53 |
apply(simp) |
|
54 |
apply(drule rep_inject[THEN iffD2]) |
|
55 |
apply(simp add: abs_inverse) |
|
56 |
done |
|
15 | 57 |
|
0 | 58 |
theorem thm11: |
59 |
shows "R r r' = (ABS r = ABS r')" |
|
60 |
unfolding ABS_def |
|
61 |
by (simp only: equiv[simplified EQUIV_def] lem7) |
|
62 |
||
4 | 63 |
|
2 | 64 |
lemma REP_ABS_rsp: |
4 | 65 |
shows "R f (REP (ABS g)) = R f g" |
66 |
and "R (REP (ABS g)) f = R g f" |
|
67 |
apply(subst thm11) |
|
68 |
apply(simp add: thm10 thm11) |
|
69 |
apply(subst thm11) |
|
70 |
apply(simp add: thm10 thm11) |
|
71 |
done |
|
72 |
||
0 | 73 |
lemma QUOTIENT: |
74 |
"QUOTIENT R ABS REP" |
|
75 |
apply(unfold QUOTIENT_def) |
|
76 |
apply(simp add: thm10) |
|
77 |
apply(simp add: REP_refl) |
|
78 |
apply(subst thm11[symmetric]) |
|
79 |
apply(simp add: equiv[simplified EQUIV_def]) |
|
80 |
done |
|
81 |
||
82 |
end |
|
83 |
||
84 |
section {* type definition for the quotient type *} |
|
85 |
||
86 |
ML {* |
|
1 | 87 |
(* constructs the term \<lambda>(c::ty \<Rightarrow> bool). \<exists>x. c = rel x *) |
0 | 88 |
fun typedef_term rel ty lthy = |
15 | 89 |
let |
90 |
val [x, c] = [("x", ty), ("c", ty --> @{typ bool})] |
|
0 | 91 |
|> Variable.variant_frees lthy [rel] |
92 |
|> map Free |
|
93 |
in |
|
15 | 94 |
lambda c |
95 |
(HOLogic.mk_exists |
|
1 | 96 |
("x", ty, HOLogic.mk_eq (c, (rel $ x)))) |
0 | 97 |
end |
98 |
*} |
|
99 |
||
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
100 |
(* |
0 | 101 |
ML {* |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
102 |
typedef_term @{term R} @{typ "nat"} @{context} |
2 | 103 |
|> Syntax.string_of_term @{context} |
104 |
|> writeln |
|
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
105 |
*}*) |
2 | 106 |
|
107 |
ML {* |
|
15 | 108 |
val typedef_tac = |
0 | 109 |
EVERY1 [rewrite_goal_tac @{thms mem_def}, |
110 |
rtac @{thm exI}, rtac @{thm exI}, rtac @{thm refl}] |
|
111 |
*} |
|
112 |
||
113 |
ML {* |
|
114 |
(* makes the new type definitions *) |
|
115 |
fun typedef_make (qty_name, rel, ty) lthy = |
|
116 |
LocalTheory.theory_result |
|
15 | 117 |
(Typedef.add_typedef false NONE |
0 | 118 |
(qty_name, map fst (Term.add_tfreesT ty []), NoSyn) |
119 |
(typedef_term rel ty lthy) |
|
120 |
NONE typedef_tac) lthy |
|
121 |
*} |
|
122 |
||
2 | 123 |
text {* proves the QUOT_TYPE theorem for the new type *} |
0 | 124 |
ML {* |
15 | 125 |
fun typedef_quot_type_tac equiv_thm (typedef_info: Typedef.info) = |
0 | 126 |
let |
127 |
val rep_thm = #Rep typedef_info |
|
128 |
val rep_inv = #Rep_inverse typedef_info |
|
129 |
val abs_inv = #Abs_inverse typedef_info |
|
130 |
val rep_inj = #Rep_inject typedef_info |
|
131 |
||
132 |
val ss = HOL_basic_ss addsimps @{thms mem_def} |
|
133 |
val rep_thm_simpd = Simplifier.asm_full_simplify ss rep_thm |
|
134 |
val abs_inv_simpd = Simplifier.asm_full_simplify ss abs_inv |
|
135 |
in |
|
136 |
EVERY1 [rtac @{thm QUOT_TYPE.intro}, |
|
15 | 137 |
rtac equiv_thm, |
138 |
rtac rep_thm_simpd, |
|
139 |
rtac rep_inv, |
|
0 | 140 |
rtac abs_inv_simpd, rtac @{thm exI}, rtac @{thm refl}, |
141 |
rtac rep_inj] |
|
142 |
end |
|
143 |
*} |
|
144 |
||
2 | 145 |
term QUOT_TYPE |
146 |
ML {* HOLogic.mk_Trueprop *} |
|
147 |
ML {* Goal.prove *} |
|
148 |
ML {* Syntax.check_term *} |
|
149 |
||
15 | 150 |
ML {* |
0 | 151 |
fun typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy = |
152 |
let |
|
153 |
val quot_type_const = Const (@{const_name "QUOT_TYPE"}, dummyT) |
|
154 |
val goal = HOLogic.mk_Trueprop (quot_type_const $ rel $ abs $ rep) |
|
155 |
|> Syntax.check_term lthy |
|
156 |
in |
|
157 |
Goal.prove lthy [] [] goal |
|
158 |
(fn _ => typedef_quot_type_tac equiv_thm typedef_info) |
|
159 |
end |
|
160 |
*} |
|
161 |
||
162 |
ML {* |
|
163 |
fun typedef_quotient_thm_tac defs quot_type_thm = |
|
15 | 164 |
EVERY1 [K (rewrite_goals_tac defs), |
165 |
rtac @{thm QUOT_TYPE.QUOTIENT}, |
|
0 | 166 |
rtac quot_type_thm] |
167 |
*} |
|
168 |
||
15 | 169 |
ML {* |
0 | 170 |
fun typedef_quotient_thm (rel, abs, rep, abs_def, rep_def, quot_type_thm) lthy = |
171 |
let |
|
172 |
val quotient_const = Const (@{const_name "QUOTIENT"}, dummyT) |
|
173 |
val goal = HOLogic.mk_Trueprop (quotient_const $ rel $ abs $ rep) |
|
174 |
|> Syntax.check_term lthy |
|
175 |
in |
|
176 |
Goal.prove lthy [] [] goal |
|
177 |
(fn _ => typedef_quotient_thm_tac [abs_def, rep_def] quot_type_thm) |
|
178 |
end |
|
179 |
*} |
|
180 |
||
181 |
text {* two wrappers for define and note *} |
|
15 | 182 |
ML {* |
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
183 |
fun make_def (name, mx, rhs) lthy = |
15 | 184 |
let |
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
185 |
val ((rhs, (_ , thm)), lthy') = |
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
186 |
LocalTheory.define Thm.internalK ((name, mx), (Attrib.empty_binding, rhs)) lthy |
0 | 187 |
in |
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
188 |
((rhs, thm), lthy') |
0 | 189 |
end |
190 |
*} |
|
191 |
||
192 |
ML {* |
|
15 | 193 |
fun reg_thm (name, thm) lthy = |
0 | 194 |
let |
15 | 195 |
val ((_,[thm']), lthy') = LocalTheory.note Thm.theoremK ((name, []), [thm]) lthy |
0 | 196 |
in |
16 | 197 |
(thm', lthy') |
0 | 198 |
end |
199 |
*} |
|
200 |
||
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
201 |
ML {* |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
202 |
val no_vars = Thm.rule_attribute (fn context => fn th => |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
203 |
let |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
204 |
val ctxt = Variable.set_body false (Context.proof_of context); |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
205 |
val ((_, [th']), _) = Variable.import true [th] ctxt; |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
206 |
in th' end); |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
207 |
*} |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
208 |
|
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
209 |
ML {* |
0 | 210 |
fun typedef_main (qty_name, rel, ty, equiv_thm) lthy = |
15 | 211 |
let |
0 | 212 |
(* generates typedef *) |
16 | 213 |
val ((_, typedef_info), lthy') = typedef_make (qty_name, rel, ty) lthy |
0 | 214 |
|
215 |
(* abs and rep functions *) |
|
216 |
val abs_ty = #abs_type typedef_info |
|
217 |
val rep_ty = #rep_type typedef_info |
|
218 |
val abs_name = #Abs_name typedef_info |
|
219 |
val rep_name = #Rep_name typedef_info |
|
220 |
val abs = Const (abs_name, rep_ty --> abs_ty) |
|
221 |
val rep = Const (rep_name, abs_ty --> rep_ty) |
|
222 |
||
223 |
(* ABS and REP definitions *) |
|
224 |
val ABS_const = Const (@{const_name "QUOT_TYPE.ABS"}, dummyT ) |
|
225 |
val REP_const = Const (@{const_name "QUOT_TYPE.REP"}, dummyT ) |
|
15 | 226 |
val ABS_trm = Syntax.check_term lthy' (ABS_const $ rel $ abs) |
227 |
val REP_trm = Syntax.check_term lthy' (REP_const $ rep) |
|
0 | 228 |
val ABS_name = Binding.prefix_name "ABS_" qty_name |
15 | 229 |
val REP_name = Binding.prefix_name "REP_" qty_name |
230 |
val (((ABS, ABS_def), (REP, REP_def)), lthy'') = |
|
0 | 231 |
lthy' |> make_def (ABS_name, NoSyn, ABS_trm) |
232 |
||>> make_def (REP_name, NoSyn, REP_trm) |
|
233 |
||
234 |
(* quot_type theorem *) |
|
235 |
val quot_thm = typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy'' |
|
236 |
val quot_thm_name = Binding.prefix_name "QUOT_TYPE_" qty_name |
|
237 |
||
238 |
(* quotient theorem *) |
|
239 |
val quotient_thm = typedef_quotient_thm (rel, ABS, REP, ABS_def, REP_def, quot_thm) lthy'' |
|
240 |
val quotient_thm_name = Binding.prefix_name "QUOTIENT_" qty_name |
|
241 |
||
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
242 |
(* interpretation *) |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
243 |
val bindd = ((Binding.make ("", Position.none)), ([]: Attrib.src list)) |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
244 |
val ((_, [eqn1pre]), lthy''') = Variable.import true [ABS_def] lthy''; |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
245 |
val eqn1i = Thm.prop_of (symmetric eqn1pre) |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
246 |
val ((_, [eqn2pre]), lthy'''') = Variable.import true [REP_def] lthy'''; |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
247 |
val eqn2i = Thm.prop_of (symmetric eqn2pre) |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
248 |
|
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
249 |
val exp_morphism = ProofContext.export_morphism lthy'''' (ProofContext.init (ProofContext.theory_of lthy'''')); |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
250 |
val exp_term = Morphism.term exp_morphism; |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
251 |
val exp = Morphism.thm exp_morphism; |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
252 |
|
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
253 |
val mthd = Method.SIMPLE_METHOD ((rtac quot_thm 1) THEN |
16 | 254 |
ALLGOALS (simp_tac (HOL_basic_ss addsimps [(symmetric (exp ABS_def)), (symmetric (exp REP_def))]))) |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
255 |
val mthdt = Method.Basic (fn _ => mthd) |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
256 |
val bymt = Proof.global_terminal_proof (mthdt, NONE) |
16 | 257 |
val exp_i = [(@{const_name QUOT_TYPE}, ((("QUOT_TYPE_I_" ^ (Binding.name_of qty_name)), true), |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
258 |
Expression.Named [ |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
259 |
("R", rel), |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
260 |
("Abs", abs), |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
261 |
("Rep", rep) |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
262 |
]))] |
0 | 263 |
in |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
264 |
lthy'''' |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
265 |
|> reg_thm (quot_thm_name, quot_thm) |
0 | 266 |
||>> reg_thm (quotient_thm_name, quotient_thm) |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
267 |
||> LocalTheory.theory (fn thy => |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
268 |
let |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
269 |
val global_eqns = map exp_term [eqn2i, eqn1i]; |
16 | 270 |
(* Not sure if the following context should not be used *) |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
271 |
val (global_eqns2, lthy''''') = Variable.import_terms true global_eqns lthy''''; |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
272 |
val global_eqns3 = map (fn t => (bindd, t)) global_eqns2; |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
273 |
in ProofContext.theory_of (bymt (Expression.interpretation (exp_i, []) global_eqns3 thy)) end) |
0 | 274 |
end |
275 |
*} |
|
276 |
||
277 |
section {* various tests for quotient types*} |
|
278 |
datatype trm = |
|
15 | 279 |
var "nat" |
0 | 280 |
| app "trm" "trm" |
281 |
| lam "nat" "trm" |
|
13
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
282 |
|
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
283 |
axiomatization RR :: "trm \<Rightarrow> trm \<Rightarrow> bool" where |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
284 |
r_eq: "EQUIV RR" |
0 | 285 |
|
2 | 286 |
ML {* |
15 | 287 |
typedef_main |
2 | 288 |
*} |
289 |
||
0 | 290 |
local_setup {* |
16 | 291 |
typedef_main (@{binding "qtrm"}, @{term "RR"}, @{typ trm}, @{thm r_eq}) #> snd |
0 | 292 |
*} |
293 |
||
294 |
term Rep_qtrm |
|
2 | 295 |
term REP_qtrm |
0 | 296 |
term Abs_qtrm |
297 |
term ABS_qtrm |
|
298 |
thm QUOT_TYPE_qtrm |
|
299 |
thm QUOTIENT_qtrm |
|
2 | 300 |
|
16 | 301 |
(* Test interpretation *) |
302 |
thm QUOT_TYPE_I_qtrm.thm11 |
|
303 |
||
0 | 304 |
thm Rep_qtrm |
305 |
||
306 |
text {* another test *} |
|
13
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
307 |
datatype 'a my = Foo |
0 | 308 |
consts Rmy :: "'a my \<Rightarrow> 'a my \<Rightarrow> bool" |
309 |
axioms rmy_eq: "EQUIV Rmy" |
|
310 |
||
311 |
term "\<lambda>(c::'a my\<Rightarrow>bool). \<exists>x. c = Rmy x" |
|
312 |
||
313 |
datatype 'a trm' = |
|
15 | 314 |
var' "'a" |
0 | 315 |
| app' "'a trm'" "'a trm'" |
316 |
| lam' "'a" "'a trm'" |
|
15 | 317 |
|
0 | 318 |
consts R' :: "'a trm' \<Rightarrow> 'a trm' \<Rightarrow> bool" |
319 |
axioms r_eq': "EQUIV R'" |
|
320 |
||
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
321 |
|
0 | 322 |
local_setup {* |
16 | 323 |
typedef_main (@{binding "qtrm'"}, @{term "R'"}, @{typ "'a trm'"}, @{thm r_eq'}) #> snd |
0 | 324 |
*} |
325 |
||
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
326 |
print_theorems |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
327 |
|
0 | 328 |
term ABS_qtrm' |
329 |
term REP_qtrm' |
|
330 |
thm QUOT_TYPE_qtrm' |
|
331 |
thm QUOTIENT_qtrm' |
|
332 |
thm Rep_qtrm' |
|
333 |
||
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
334 |
|
0 | 335 |
text {* a test with lists of terms *} |
336 |
datatype t = |
|
337 |
vr "string" |
|
338 |
| ap "t list" |
|
339 |
| lm "string" "t" |
|
340 |
||
341 |
consts Rt :: "t \<Rightarrow> t \<Rightarrow> bool" |
|
342 |
axioms t_eq: "EQUIV Rt" |
|
343 |
||
344 |
local_setup {* |
|
345 |
typedef_main (@{binding "qt"}, @{term "Rt"}, @{typ "t"}, @{thm t_eq}) #> snd |
|
346 |
*} |
|
347 |
||
348 |
section {* lifting of constants *} |
|
349 |
||
350 |
text {* information about map-functions for type-constructor *} |
|
351 |
ML {* |
|
352 |
type typ_info = {mapfun: string} |
|
353 |
||
354 |
local |
|
355 |
structure Data = GenericDataFun |
|
356 |
(type T = typ_info Symtab.table |
|
357 |
val empty = Symtab.empty |
|
358 |
val extend = I |
|
359 |
fun merge _ = Symtab.merge (K true)) |
|
360 |
in |
|
361 |
val lookup = Symtab.lookup o Data.get |
|
15 | 362 |
fun update k v = Data.map (Symtab.update (k, v)) |
0 | 363 |
end |
364 |
*} |
|
365 |
||
366 |
(* mapfuns for some standard types *) |
|
367 |
setup {* |
|
368 |
Context.theory_map (update @{type_name "list"} {mapfun = @{const_name "map"}}) |
|
369 |
#> Context.theory_map (update @{type_name "*"} {mapfun = @{const_name "prod_fun"}}) |
|
370 |
#> Context.theory_map (update @{type_name "fun"} {mapfun = @{const_name "fun_map"}}) |
|
371 |
*} |
|
372 |
||
2 | 373 |
|
0 | 374 |
ML {* lookup (Context.Proof @{context}) @{type_name list} *} |
375 |
||
376 |
ML {* |
|
377 |
datatype abs_or_rep = abs | rep |
|
378 |
||
15 | 379 |
fun get_fun abs_or_rep rty qty lthy ty = |
0 | 380 |
let |
381 |
val qty_name = Long_Name.base_name (fst (dest_Type qty)) |
|
15 | 382 |
|
0 | 383 |
fun get_fun_aux s fs_tys = |
384 |
let |
|
385 |
val (fs, tys) = split_list fs_tys |
|
15 | 386 |
val (otys, ntys) = split_list tys |
0 | 387 |
val oty = Type (s, otys) |
388 |
val nty = Type (s, ntys) |
|
389 |
val ftys = map (op -->) tys |
|
390 |
in |
|
15 | 391 |
(case (lookup (Context.Proof lthy) s) of |
0 | 392 |
SOME info => (list_comb (Const (#mapfun info, ftys ---> oty --> nty), fs), (oty, nty)) |
393 |
| NONE => raise ERROR ("no map association for type " ^ s)) |
|
394 |
end |
|
395 |
||
396 |
fun get_const abs = (Const ("QuotMain.ABS_" ^ qty_name, rty --> qty), (rty, qty)) |
|
397 |
| get_const rep = (Const ("QuotMain.REP_" ^ qty_name, qty --> rty), (qty, rty)) |
|
398 |
in |
|
399 |
if ty = qty |
|
400 |
then (get_const abs_or_rep) |
|
401 |
else (case ty of |
|
402 |
TFree _ => (Abs ("x", ty, Bound 0), (ty, ty)) |
|
403 |
| Type (_, []) => (Abs ("x", ty, Bound 0), (ty, ty)) |
|
15 | 404 |
| Type (s, tys) => get_fun_aux s (map (get_fun abs_or_rep rty qty lthy) tys) |
0 | 405 |
| _ => raise ERROR ("no variables") |
406 |
) |
|
407 |
end |
|
408 |
*} |
|
409 |
||
410 |
ML {* |
|
2 | 411 |
get_fun rep @{typ t} @{typ qt} @{context} @{typ "t * nat"} |
412 |
|> fst |
|
413 |
|> Syntax.string_of_term @{context} |
|
414 |
|> writeln |
|
415 |
*} |
|
416 |
||
417 |
||
418 |
ML {* |
|
0 | 419 |
fun get_const_def nconst oconst rty qty lthy = |
420 |
let |
|
421 |
val ty = fastype_of nconst |
|
422 |
val (arg_tys, res_ty) = strip_type ty |
|
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
423 |
|
0 | 424 |
val fresh_args = arg_tys |> map (pair "x") |
15 | 425 |
|> Variable.variant_frees lthy [nconst, oconst] |
0 | 426 |
|> map Free |
427 |
||
428 |
val rep_fns = map (fst o get_fun rep rty qty lthy) arg_tys |
|
429 |
val abs_fn = (fst o get_fun abs rty qty lthy) res_ty |
|
430 |
||
431 |
in |
|
432 |
map (op $) (rep_fns ~~ fresh_args) |
|
433 |
|> curry list_comb oconst |
|
434 |
|> curry (op $) abs_fn |
|
435 |
|> fold_rev lambda fresh_args |
|
436 |
end |
|
437 |
*} |
|
438 |
||
439 |
ML {* |
|
15 | 440 |
fun exchange_ty rty qty ty = |
0 | 441 |
if ty = rty then qty |
15 | 442 |
else |
0 | 443 |
(case ty of |
444 |
Type (s, tys) => Type (s, map (exchange_ty rty qty) tys) |
|
445 |
| _ => ty) |
|
446 |
*} |
|
447 |
||
448 |
ML {* |
|
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
449 |
fun make_const_def nconst_bname oconst mx rty qty lthy = |
0 | 450 |
let |
451 |
val oconst_ty = fastype_of oconst |
|
452 |
val nconst_ty = exchange_ty rty qty oconst_ty |
|
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
453 |
val nconst = Const (Binding.name_of nconst_bname, nconst_ty) |
0 | 454 |
val def_trm = get_const_def nconst oconst rty qty lthy |
455 |
in |
|
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
456 |
make_def (nconst_bname, mx, def_trm) lthy |
15 | 457 |
end |
0 | 458 |
*} |
459 |
||
2 | 460 |
local_setup {* |
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
461 |
make_const_def @{binding VR} @{term "vr"} NoSyn @{typ "t"} @{typ "qt"} #> snd |
2 | 462 |
*} |
463 |
||
464 |
local_setup {* |
|
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
465 |
make_const_def @{binding AP} @{term "ap"} NoSyn @{typ "t"} @{typ "qt"} #> snd |
2 | 466 |
*} |
467 |
||
468 |
local_setup {* |
|
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
469 |
make_const_def @{binding LM} @{term "lm"} NoSyn @{typ "t"} @{typ "qt"} #> snd |
2 | 470 |
*} |
471 |
||
472 |
thm VR_def |
|
473 |
thm AP_def |
|
474 |
thm LM_def |
|
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
475 |
term LM |
2 | 476 |
term VR |
477 |
term AP |
|
478 |
||
479 |
||
0 | 480 |
text {* a test with functions *} |
481 |
datatype 'a t' = |
|
482 |
vr' "string" |
|
483 |
| ap' "('a t') * ('a t')" |
|
484 |
| lm' "'a" "string \<Rightarrow> ('a t')" |
|
485 |
||
486 |
consts Rt' :: "('a t') \<Rightarrow> ('a t') \<Rightarrow> bool" |
|
487 |
axioms t_eq': "EQUIV Rt'" |
|
488 |
||
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
489 |
|
0 | 490 |
local_setup {* |
491 |
typedef_main (@{binding "qt'"}, @{term "Rt'"}, @{typ "'a t'"}, @{thm t_eq'}) #> snd |
|
492 |
*} |
|
493 |
||
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
494 |
print_theorems |
2 | 495 |
|
0 | 496 |
local_setup {* |
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
497 |
make_const_def @{binding VR'} @{term "vr'"} NoSyn @{typ "'a t'"} @{typ "'a qt'"} #> snd |
0 | 498 |
*} |
499 |
||
500 |
local_setup {* |
|
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
501 |
make_const_def @{binding AP'} @{term "ap'"} NoSyn @{typ "'a t'"} @{typ "'a qt'"} #> snd |
0 | 502 |
*} |
503 |
||
504 |
local_setup {* |
|
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
505 |
make_const_def @{binding LM'} @{term "lm'"} NoSyn @{typ "'a t'"} @{typ "'a qt'"} #> snd |
0 | 506 |
*} |
507 |
||
508 |
thm VR'_def |
|
509 |
thm AP'_def |
|
510 |
thm LM'_def |
|
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
511 |
term LM' |
0 | 512 |
term VR' |
513 |
term AP' |
|
514 |
||
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
515 |
|
0 | 516 |
text {* finite set example *} |
13
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
517 |
print_syntax |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
518 |
inductive |
13
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
519 |
list_eq (infix "\<approx>" 50) |
0 | 520 |
where |
521 |
"a#b#xs \<approx> b#a#xs" |
|
522 |
| "[] \<approx> []" |
|
523 |
| "xs \<approx> ys \<Longrightarrow> ys \<approx> xs" |
|
524 |
| "a#a#xs \<approx> a#xs" |
|
525 |
| "xs \<approx> ys \<Longrightarrow> a#xs \<approx> a#ys" |
|
526 |
| "\<lbrakk>xs1 \<approx> xs2; xs2 \<approx> xs3\<rbrakk> \<Longrightarrow> xs1 \<approx> xs3" |
|
527 |
||
528 |
lemma list_eq_sym: |
|
529 |
shows "xs \<approx> xs" |
|
13
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
530 |
apply (induct xs) |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
531 |
apply (auto intro: list_eq.intros) |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
532 |
done |
0 | 533 |
|
534 |
lemma equiv_list_eq: |
|
535 |
shows "EQUIV list_eq" |
|
13
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
536 |
unfolding EQUIV_REFL_SYM_TRANS REFL_def SYM_def TRANS_def |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
537 |
apply(auto intro: list_eq.intros list_eq_sym) |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
538 |
done |
0 | 539 |
|
540 |
local_setup {* |
|
541 |
typedef_main (@{binding "fset"}, @{term "list_eq"}, @{typ "'a list"}, @{thm "equiv_list_eq"}) #> snd |
|
542 |
*} |
|
543 |
||
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
544 |
print_theorems |
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
545 |
|
0 | 546 |
typ "'a fset" |
547 |
thm "Rep_fset" |
|
548 |
||
549 |
local_setup {* |
|
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
550 |
make_const_def @{binding EMPTY} @{term "[]"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd |
0 | 551 |
*} |
552 |
||
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
553 |
term Nil |
0 | 554 |
term EMPTY |
2 | 555 |
thm EMPTY_def |
556 |
||
0 | 557 |
|
558 |
local_setup {* |
|
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
559 |
make_const_def @{binding INSERT} @{term "op #"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd |
0 | 560 |
*} |
561 |
||
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
562 |
term Cons |
0 | 563 |
term INSERT |
2 | 564 |
thm INSERT_def |
0 | 565 |
|
566 |
local_setup {* |
|
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
567 |
make_const_def @{binding UNION} @{term "op @"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd |
0 | 568 |
*} |
569 |
||
15 | 570 |
term append |
0 | 571 |
term UNION |
2 | 572 |
thm UNION_def |
573 |
||
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
574 |
(* Maybe the infrastructure should not allow this kind of definition, without showing that |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
575 |
the relation respects lenght... *) |
7
3e77ad0abc6a
- Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
6
diff
changeset
|
576 |
local_setup {* |
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
577 |
make_const_def @{binding CARD} @{term "length"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd |
7
3e77ad0abc6a
- Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
6
diff
changeset
|
578 |
*} |
3e77ad0abc6a
- Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
6
diff
changeset
|
579 |
|
3e77ad0abc6a
- Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
6
diff
changeset
|
580 |
term length |
3e77ad0abc6a
- Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
6
diff
changeset
|
581 |
term CARD |
3e77ad0abc6a
- Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
6
diff
changeset
|
582 |
thm CARD_def |
3e77ad0abc6a
- Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
6
diff
changeset
|
583 |
|
0 | 584 |
thm QUOTIENT_fset |
585 |
||
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
586 |
thm QUOT_TYPE_I_fset.thm11 |
9
eac147a5eb33
Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
8
diff
changeset
|
587 |
|
eac147a5eb33
Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
8
diff
changeset
|
588 |
|
13
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
589 |
fun |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
590 |
membship :: "'a \<Rightarrow> 'a list \<Rightarrow> bool" (infix "memb" 100) |
0 | 591 |
where |
592 |
m1: "(x memb []) = False" |
|
593 |
| m2: "(x memb (y#xs)) = ((x=y) \<or> (x memb xs))" |
|
594 |
||
2 | 595 |
lemma mem_respects: |
9
eac147a5eb33
Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
8
diff
changeset
|
596 |
fixes z |
2 | 597 |
assumes a: "list_eq x y" |
9
eac147a5eb33
Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
8
diff
changeset
|
598 |
shows "(z memb x) = (z memb y)" |
13
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
599 |
using a by induct auto |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
600 |
|
2 | 601 |
|
12 | 602 |
lemma cons_preserves: |
603 |
fixes z |
|
604 |
assumes a: "xs \<approx> ys" |
|
605 |
shows "(z # xs) \<approx> (z # ys)" |
|
13
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
606 |
using a by (rule QuotMain.list_eq.intros(5)) |
12 | 607 |
|
11
0bc0db2e83f2
Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
10
diff
changeset
|
608 |
ML {* |
0bc0db2e83f2
Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
10
diff
changeset
|
609 |
fun unlam_def orig_ctxt ctxt t = |
13
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
610 |
let val rhs = Thm.rhs_of t in |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
611 |
(case try (Thm.dest_abs NONE) rhs of |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
612 |
SOME (v, vt) => |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
613 |
let |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
614 |
val (vname, vt) = Term.dest_Free (Thm.term_of v) |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
615 |
val ([vnname], ctxt) = Variable.variant_fixes [vname] ctxt |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
616 |
val nv = Free(vnname, vt) |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
617 |
val t2 = Drule.fun_cong_rule t (Thm.cterm_of (ProofContext.theory_of ctxt) nv) |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
618 |
val tnorm = equal_elim (Drule.beta_eta_conversion (Thm.cprop_of t2)) t2 |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
619 |
in unlam_def orig_ctxt ctxt tnorm end |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
620 |
| NONE => singleton (ProofContext.export ctxt orig_ctxt) t) |
c13bb9e02eb7
Fixes after suggestions from Makarius:
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
12
diff
changeset
|
621 |
end |
10
b11b405b8271
Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
9
diff
changeset
|
622 |
*} |
9
eac147a5eb33
Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
8
diff
changeset
|
623 |
|
10
b11b405b8271
Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
9
diff
changeset
|
624 |
local_setup {* |
17
55b646c6c4cd
More naming/binding suggestions from Makarius
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
16
diff
changeset
|
625 |
make_const_def @{binding IN} @{term "membship"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd |
10
b11b405b8271
Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
9
diff
changeset
|
626 |
*} |
b11b405b8271
Make both kinds of definitions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
9
diff
changeset
|
627 |
|
0 | 628 |
term membship |
629 |
term IN |
|
2 | 630 |
thm IN_def |
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
631 |
ML {* unlam_def @{context} @{context} @{thm IN_def} *} |
0 | 632 |
|
2 | 633 |
lemmas a = QUOT_TYPE.ABS_def[OF QUOT_TYPE_fset] |
634 |
thm QUOT_TYPE.thm11[OF QUOT_TYPE_fset, THEN iffD1, simplified a] |
|
0 | 635 |
|
2 | 636 |
lemma yy: |
637 |
shows "(False = x memb []) = (False = IN (x::nat) EMPTY)" |
|
638 |
unfolding IN_def EMPTY_def |
|
639 |
apply(rule_tac f="(op =) False" in arg_cong) |
|
640 |
apply(rule mem_respects) |
|
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
641 |
apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp) |
2 | 642 |
apply(rule list_eq.intros) |
0 | 643 |
done |
644 |
||
2 | 645 |
lemma |
646 |
shows "IN (x::nat) EMPTY = False" |
|
647 |
using m1 |
|
648 |
apply - |
|
649 |
apply(rule yy[THEN iffD1, symmetric]) |
|
650 |
apply(simp) |
|
0 | 651 |
done |
652 |
||
2 | 653 |
lemma |
654 |
shows "((x=y) \<or> (IN x xs) = (IN (x::nat) (INSERT y xs))) = |
|
655 |
((x = y) \<or> x memb REP_fset xs = x memb (y # REP_fset xs))" |
|
656 |
unfolding IN_def INSERT_def |
|
657 |
apply(rule_tac f="(op \<or>) (x=y)" in arg_cong) |
|
658 |
apply(rule_tac f="(op =) (x memb REP_fset xs)" in arg_cong) |
|
659 |
apply(rule mem_respects) |
|
660 |
apply(rule list_eq.intros(3)) |
|
661 |
apply(unfold REP_fset_def ABS_fset_def) |
|
5 | 662 |
apply(simp only: QUOT_TYPE.REP_ABS_rsp[OF QUOT_TYPE_fset]) |
2 | 663 |
apply(rule list_eq_sym) |
664 |
done |
|
0 | 665 |
|
7
3e77ad0abc6a
- Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
6
diff
changeset
|
666 |
lemma append_respects_fst: |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
667 |
assumes a : "list_eq l1 l2" |
4 | 668 |
shows "list_eq (l1 @ s) (l2 @ s)" |
3 | 669 |
using a |
670 |
apply(induct) |
|
4 | 671 |
apply(auto intro: list_eq.intros) |
672 |
apply(simp add: list_eq_sym) |
|
3 | 673 |
done |
674 |
||
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
675 |
lemma yyy: |
3 | 676 |
shows " |
677 |
( |
|
678 |
(UNION EMPTY s = s) & |
|
679 |
((UNION (INSERT e s1) s2) = (INSERT e (UNION s1 s2))) |
|
680 |
) = ( |
|
681 |
((ABS_fset ([] @ REP_fset s)) = s) & |
|
682 |
((ABS_fset ((e # (REP_fset s1)) @ REP_fset s2)) = ABS_fset (e # (REP_fset s1 @ REP_fset s2))) |
|
683 |
)" |
|
684 |
unfolding UNION_def EMPTY_def INSERT_def |
|
685 |
apply(rule_tac f="(op &)" in arg_cong2) |
|
686 |
apply(rule_tac f="(op =)" in arg_cong2) |
|
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
687 |
apply(simp only: QUOT_TYPE_I_fset.thm11[symmetric]) |
7
3e77ad0abc6a
- Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
6
diff
changeset
|
688 |
apply(rule append_respects_fst) |
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
689 |
apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp) |
3 | 690 |
apply(rule list_eq_sym) |
691 |
apply(simp) |
|
692 |
apply(rule_tac f="(op =)" in arg_cong2) |
|
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
693 |
apply(simp only: QUOT_TYPE_I_fset.thm11[symmetric]) |
7
3e77ad0abc6a
- Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
6
diff
changeset
|
694 |
apply(rule append_respects_fst) |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
695 |
apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp) |
3 | 696 |
apply(rule list_eq_sym) |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
697 |
apply(simp only: QUOT_TYPE_I_fset.thm11[symmetric]) |
3 | 698 |
apply(rule list_eq.intros(5)) |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
699 |
apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp) |
3 | 700 |
apply(rule list_eq_sym) |
701 |
done |
|
702 |
||
703 |
lemma |
|
704 |
shows " |
|
705 |
(UNION EMPTY s = s) & |
|
7
3e77ad0abc6a
- Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
6
diff
changeset
|
706 |
((UNION (INSERT e s1) s2) = (INSERT e (UNION s1 s2)))" |
3e77ad0abc6a
- Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
6
diff
changeset
|
707 |
apply (simp add: yyy) |
14
5f6ee943c697
Generalized interpretation, works for all examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
13
diff
changeset
|
708 |
apply (rule QUOT_TYPE_I_fset.thm10) |
7
3e77ad0abc6a
- Build an interpretation for fset from ML level and use it
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
6
diff
changeset
|
709 |
done |
3 | 710 |
|
8
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
711 |
ML {* |
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
712 |
fun mk_rep_abs x = @{term REP_fset} $ (@{term ABS_fset} $ x) |
12 | 713 |
val consts = [@{const_name "Nil"}, @{const_name "append"}, @{const_name "Cons"}, @{const_name "membship"}] |
8
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
714 |
*} |
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
715 |
|
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
716 |
ML {* |
12 | 717 |
fun build_goal thm constructors lifted_type mk_rep_abs = |
8
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
718 |
let |
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
719 |
fun is_const (Const (x, t)) = x mem constructors |
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
720 |
| is_const _ = false |
12 | 721 |
fun maybe_mk_rep_abs t = |
722 |
let |
|
723 |
val _ = writeln ("Maybe: " ^ Syntax.string_of_term @{context} t) |
|
724 |
in |
|
725 |
if type_of t = lifted_type then mk_rep_abs t else t |
|
726 |
end |
|
8
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
727 |
fun build_aux (Abs (s, t, tr)) = (Abs (s, t, build_aux tr)) |
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
728 |
| build_aux (f $ a) = |
11
0bc0db2e83f2
Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
10
diff
changeset
|
729 |
let |
16 | 730 |
val (f, args) = strip_comb (f $ a) |
12 | 731 |
val _ = writeln (Syntax.string_of_term @{context} f) |
11
0bc0db2e83f2
Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
10
diff
changeset
|
732 |
in |
12 | 733 |
(if is_const f then maybe_mk_rep_abs (list_comb (f, (map maybe_mk_rep_abs (map build_aux args)))) |
11
0bc0db2e83f2
Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
10
diff
changeset
|
734 |
else list_comb ((build_aux f), (map build_aux args))) |
0bc0db2e83f2
Use metavariables in the 'non-lambda' definitions
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
10
diff
changeset
|
735 |
end |
8
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
736 |
| build_aux x = |
12 | 737 |
if is_const x then maybe_mk_rep_abs x else x |
9
eac147a5eb33
Changed to the use of "modern interface"
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
8
diff
changeset
|
738 |
val concl = HOLogic.dest_Trueprop (Thm.concl_of thm) |
8
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
739 |
in |
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
740 |
HOLogic.mk_eq ((build_aux concl), concl) |
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
741 |
end *} |
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
742 |
|
16 | 743 |
ML {* val emptyt = (symmetric (unlam_def @{context} @{context} @{thm EMPTY_def})) *} |
744 |
ML {* val in_t = (symmetric (unlam_def @{context} @{context} @{thm IN_def})) *} |
|
745 |
ML {* val uniont = symmetric (unlam_def @{context} @{context} @{thm UNION_def}) *} |
|
746 |
ML {* val cardt = symmetric (unlam_def @{context} @{context} @{thm CARD_def}) *} |
|
747 |
ML {* val insertt = symmetric (unlam_def @{context} @{context} @{thm INSERT_def}) *} |
|
8
54afbcf2a758
Initial version of the function that builds goals.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
7
diff
changeset
|
748 |
|
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
749 |
notation ( output) "prop" ("#_" [1000] 1000) |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
750 |
|
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
751 |
ML {* @{thm arg_cong2} *} |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
752 |
ML {* rtac *} |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
753 |
ML {* Term.dest_Const @{term "op ="} *} |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
754 |
|
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
755 |
ML {* |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
756 |
fun dest_cbinop t = |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
757 |
let |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
758 |
val (t2, rhs) = Thm.dest_comb t; |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
759 |
val (bop, lhs) = Thm.dest_comb t2; |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
760 |
in |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
761 |
(bop, (lhs, rhs)) |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
762 |
end |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
763 |
*} |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
764 |
ML {* |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
765 |
fun dest_ceq t = |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
766 |
let |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
767 |
val (bop, pair) = dest_cbinop t; |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
768 |
val (bop_s, _) = Term.dest_Const (Thm.term_of bop); |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
769 |
in |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
770 |
if bop_s = "op =" then pair else (raise CTERM ("Not an equality", [t])) |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
771 |
end |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
772 |
*} |
19
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
773 |
ML Thm.instantiate |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
774 |
ML {*@{thm arg_cong2}*} |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
775 |
ML {*@{thm arg_cong2[of _ _ _ _ "op ="]} *} |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
776 |
ML {* val cT = @{cpat "op ="} |> Thm.ctyp_of_term |> Thm.dest_ctyp |> hd *} |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
777 |
ML {* |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
778 |
Toplevel.program (fn () => |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
779 |
Drule.instantiate' [SOME cT,SOME cT,SOME @{ctyp bool}] [NONE,NONE,NONE,NONE,SOME (@{cpat "op ="})] @{thm arg_cong2} |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
780 |
) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
781 |
*} |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
782 |
|
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
783 |
ML {* |
19
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
784 |
fun foo_conv t = |
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
785 |
let |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
786 |
val (lhs, rhs) = dest_ceq t; |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
787 |
val (bop, _) = dest_cbinop lhs; |
19
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
788 |
val [clT, cr2] = bop |> Thm.ctyp_of_term |> Thm.dest_ctyp; |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
789 |
val [cmT, crT] = Thm.dest_ctyp cr2; |
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
790 |
in |
19
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
791 |
Drule.instantiate' [SOME clT,SOME cmT,SOME crT] [NONE,NONE,NONE,NONE,SOME bop] @{thm arg_cong2} |
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
792 |
end |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
793 |
*} |
19
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
794 |
|
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
795 |
ML ORELSE |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
796 |
|
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
797 |
ML {* |
19
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
798 |
fun foo_tac n thm = |
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
799 |
let |
19
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
800 |
val concl = Thm.cprem_of thm n; |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
801 |
val (_, cconcl) = Thm.dest_comb concl; |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
802 |
val rewr = foo_conv cconcl; |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
803 |
val _ = tracing (Display.string_of_thm @{context} rewr) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
804 |
val _ = tracing (Display.string_of_thm @{context} thm) |
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
805 |
in |
19
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
806 |
rtac rewr n thm |
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
807 |
end |
19
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
808 |
handle CTERM _ => Seq.empty |
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
809 |
*} |
19
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
810 |
|
20
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
811 |
(* Has all the theorems about fset plugged in. These should be parameters to the tactic *) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
812 |
|
19
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
813 |
ML {* |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
814 |
val foo_tac' = |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
815 |
FIRST' [ |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
816 |
rtac @{thm list_eq_sym}, |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
817 |
rtac @{thm cons_preserves}, |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
818 |
rtac @{thm mem_respects}, |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
819 |
foo_tac, |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
820 |
simp_tac (@{simpset} addsimps @{thms QUOT_TYPE_I_fset.REP_ABS_rsp}) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
821 |
] |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
822 |
*} |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
823 |
|
20
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
824 |
thm m1 |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
825 |
|
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
826 |
ML {* |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
827 |
val m1_novars = snd(no_vars ((Context.Theory @{theory}),@{thm m1})) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
828 |
val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
829 |
val cgoal = cterm_of @{theory} goal |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
830 |
val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false [emptyt, in_t] cgoal) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
831 |
*} |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
832 |
|
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
833 |
prove {* HOLogic.mk_Trueprop (Thm.term_of cgoal2) *} |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
834 |
apply (tactic {* foo_tac' 1 *}) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
835 |
unfolding IN_def EMPTY_def |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
836 |
apply (tactic {* foo_tac' 1 *}) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
837 |
apply (tactic {* foo_tac' 1 *}) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
838 |
apply (tactic {* foo_tac' 1 *}) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
839 |
apply (tactic {* foo_tac' 1 *}) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
840 |
done |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
841 |
|
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
842 |
|
20
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
843 |
thm length_append (* Not true but worth checking that the goal is correct *) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
844 |
ML {* |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
845 |
val m1_novars = snd(no_vars ((Context.Theory @{theory}),@{thm length_append})) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
846 |
val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
847 |
val cgoal = cterm_of @{theory} goal |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
848 |
val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false [emptyt, in_t, cardt, uniont] cgoal) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
849 |
*} |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
850 |
(* prove {* HOLogic.mk_Trueprop (Thm.term_of cgoal2) *} |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
851 |
apply (tactic {* foo_tac' 1 *}) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
852 |
apply (tactic {* foo_tac' 2 *}) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
853 |
apply (tactic {* foo_tac' 2 *}) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
854 |
apply (tactic {* foo_tac' 2 *}) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
855 |
unfolding CARD_def UNION_def |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
856 |
apply (tactic {* foo_tac' 1 *}) *) |
19
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
857 |
|
20
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
858 |
thm m2 |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
859 |
ML {* |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
860 |
val m1_novars = snd(no_vars ((Context.Theory @{theory}),@{thm m2})) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
861 |
val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
862 |
val cgoal = cterm_of @{theory} goal |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
863 |
val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false [emptyt, in_t, cardt, uniont, insertt] cgoal) |
ccc220a23887
Testing the tactic further.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
19
diff
changeset
|
864 |
*} |
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
865 |
prove {* HOLogic.mk_Trueprop (Thm.term_of cgoal2) *} |
19
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
866 |
apply (tactic {* foo_tac' 1 *}) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
867 |
unfolding IN_def INSERT_def |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
868 |
apply (tactic {* foo_tac' 1 *}) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
869 |
apply (tactic {* foo_tac' 1 *}) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
870 |
apply (tactic {* foo_tac' 1 *}) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
871 |
apply (tactic {* foo_tac' 1 *}) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
872 |
apply (tactic {* foo_tac' 1 *}) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
873 |
apply (tactic {* foo_tac' 1 *}) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
874 |
apply (tactic {* foo_tac' 1 *}) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
875 |
apply (tactic {* foo_tac' 1 *}) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
876 |
apply (tactic {* foo_tac' 1 *}) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
877 |
apply (tactic {* foo_tac' 1 *}) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
878 |
apply (tactic {* foo_tac' 1 *}) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
879 |
apply (tactic {* foo_tac' 1 *}) |
55aefc2d524a
The tactic still only for fset
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
18
diff
changeset
|
880 |
done |
18
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
881 |
|
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
882 |
(* |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
883 |
datatype obj1 = |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
884 |
OVAR1 "string" |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
885 |
| OBJ1 "(string * (string \<Rightarrow> obj1)) list" |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
886 |
| INVOKE1 "obj1 \<Rightarrow> string" |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
887 |
| UPDATE1 "obj1 \<Rightarrow> string \<Rightarrow> (string \<Rightarrow> obj1)" |
ce522150c1f7
Infrastructure for the tactic
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
17
diff
changeset
|
888 |
*) |