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