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