72 end |
78 end |
73 |
79 |
74 section {* type definition for the quotient type *} |
80 section {* type definition for the quotient type *} |
75 |
81 |
76 ML {* |
82 ML {* |
|
83 Variable.variant_frees |
|
84 *} |
|
85 |
|
86 |
|
87 ML {* |
77 (* constructs the term \<lambda>(c::ty \<Rightarrow> bool). \<exists>x. c = rel x *) |
88 (* constructs the term \<lambda>(c::ty \<Rightarrow> bool). \<exists>x. c = rel x *) |
78 fun typedef_term rel ty lthy = |
89 fun typedef_term rel ty lthy = |
79 let |
90 let |
80 val [x, c] = [("x", ty), ("c", ty --> @{typ bool})] |
91 val [x, c] = [("x", ty), ("c", ty --> @{typ bool})] |
81 |> Variable.variant_frees lthy [rel] |
92 |> Variable.variant_frees lthy [rel] |
101 (qty_name, map fst (Term.add_tfreesT ty []), NoSyn) |
118 (qty_name, map fst (Term.add_tfreesT ty []), NoSyn) |
102 (typedef_term rel ty lthy) |
119 (typedef_term rel ty lthy) |
103 NONE typedef_tac) lthy |
120 NONE typedef_tac) lthy |
104 *} |
121 *} |
105 |
122 |
106 text {* proves the QUOTIENT theorem for the new type *} |
123 text {* proves the QUOT_TYPE theorem for the new type *} |
107 ML {* |
124 ML {* |
108 fun typedef_quot_type_tac equiv_thm (typedef_info: Typedef.info) = |
125 fun typedef_quot_type_tac equiv_thm (typedef_info: Typedef.info) = |
109 let |
126 let |
110 val rep_thm = #Rep typedef_info |
127 val rep_thm = #Rep typedef_info |
111 val rep_inv = #Rep_inverse typedef_info |
128 val rep_inv = #Rep_inverse typedef_info |
122 rtac rep_inv, |
139 rtac rep_inv, |
123 rtac abs_inv_simpd, rtac @{thm exI}, rtac @{thm refl}, |
140 rtac abs_inv_simpd, rtac @{thm exI}, rtac @{thm refl}, |
124 rtac rep_inj] |
141 rtac rep_inj] |
125 end |
142 end |
126 *} |
143 *} |
|
144 |
|
145 term QUOT_TYPE |
|
146 ML {* HOLogic.mk_Trueprop *} |
|
147 ML {* Goal.prove *} |
|
148 ML {* Syntax.check_term *} |
127 |
149 |
128 ML {* |
150 ML {* |
129 fun typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy = |
151 fun typedef_quot_type_thm (rel, abs, rep, equiv_thm, typedef_info) lthy = |
130 let |
152 let |
131 val quot_type_const = Const (@{const_name "QUOT_TYPE"}, dummyT) |
153 val quot_type_const = Const (@{const_name "QUOT_TYPE"}, dummyT) |
223 | lam "nat" "trm" |
245 | lam "nat" "trm" |
224 |
246 |
225 consts R :: "trm \<Rightarrow> trm \<Rightarrow> bool" |
247 consts R :: "trm \<Rightarrow> trm \<Rightarrow> bool" |
226 axioms r_eq: "EQUIV R" |
248 axioms r_eq: "EQUIV R" |
227 |
249 |
|
250 ML {* |
|
251 typedef_main |
|
252 *} |
|
253 |
228 local_setup {* |
254 local_setup {* |
229 typedef_main (@{binding "qtrm"}, @{term "R"}, @{typ trm}, @{thm r_eq}) #> snd |
255 typedef_main (@{binding "qtrm"}, @{term "R"}, @{typ trm}, @{thm r_eq}) #> snd |
230 *} |
256 *} |
231 |
257 |
232 term Rep_qtrm |
258 term Rep_qtrm |
|
259 term REP_qtrm |
233 term Abs_qtrm |
260 term Abs_qtrm |
234 term ABS_qtrm |
261 term ABS_qtrm |
235 term REP_qtrm |
|
236 thm QUOT_TYPE_qtrm |
262 thm QUOT_TYPE_qtrm |
237 thm QUOTIENT_qtrm |
263 thm QUOTIENT_qtrm |
|
264 |
238 thm Rep_qtrm |
265 thm Rep_qtrm |
239 |
266 |
240 text {* another test *} |
267 text {* another test *} |
241 datatype 'a my = foo |
268 datatype 'a my = foo |
242 consts Rmy :: "'a my \<Rightarrow> 'a my \<Rightarrow> bool" |
269 consts Rmy :: "'a my \<Rightarrow> 'a my \<Rightarrow> bool" |
376 in |
412 in |
377 make_def (Binding.name nconst_name, mx, def_trm) lthy |
413 make_def (Binding.name nconst_name, mx, def_trm) lthy |
378 end |
414 end |
379 *} |
415 *} |
380 |
416 |
|
417 local_setup {* |
|
418 make_const_def "VR" @{term "vr"} NoSyn @{typ "t"} @{typ "qt"} #> snd |
|
419 *} |
|
420 |
|
421 local_setup {* |
|
422 make_const_def "AP" @{term "ap"} NoSyn @{typ "t"} @{typ "qt"} #> snd |
|
423 *} |
|
424 |
|
425 local_setup {* |
|
426 make_const_def "LM" @{term "lm"} NoSyn @{typ "t"} @{typ "qt"} #> snd |
|
427 *} |
|
428 |
|
429 thm VR_def |
|
430 thm AP_def |
|
431 thm LM_def |
|
432 term LM |
|
433 term VR |
|
434 term AP |
|
435 |
|
436 |
381 text {* a test with functions *} |
437 text {* a test with functions *} |
382 datatype 'a t' = |
438 datatype 'a t' = |
383 vr' "string" |
439 vr' "string" |
384 | ap' "('a t') * ('a t')" |
440 | ap' "('a t') * ('a t')" |
385 | lm' "'a" "string \<Rightarrow> ('a t')" |
441 | lm' "'a" "string \<Rightarrow> ('a t')" |
445 make_const_def "EMPTY" @{term "[]"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd |
502 make_const_def "EMPTY" @{term "[]"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd |
446 *} |
503 *} |
447 |
504 |
448 term Nil |
505 term Nil |
449 term EMPTY |
506 term EMPTY |
|
507 thm EMPTY_def |
|
508 |
450 |
509 |
451 local_setup {* |
510 local_setup {* |
452 make_const_def "INSERT" @{term "op #"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd |
511 make_const_def "INSERT" @{term "op #"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd |
453 *} |
512 *} |
454 |
513 |
455 term Cons |
514 term Cons |
456 term INSERT |
515 term INSERT |
|
516 thm INSERT_def |
457 |
517 |
458 local_setup {* |
518 local_setup {* |
459 make_const_def "UNION" @{term "op @"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd |
519 make_const_def "UNION" @{term "op @"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd |
460 *} |
520 *} |
461 |
521 |
462 term append |
522 term append |
463 term UNION |
523 term UNION |
|
524 thm UNION_def |
|
525 |
464 thm QUOTIENT_fset |
526 thm QUOTIENT_fset |
465 thm Insert_def |
|
466 |
527 |
467 fun |
528 fun |
468 membship :: "'a \<Rightarrow> 'a list \<Rightarrow> bool" ("_ memb _") |
529 membship :: "'a \<Rightarrow> 'a list \<Rightarrow> bool" ("_ memb _") |
469 where |
530 where |
470 m1: "(x memb []) = False" |
531 m1: "(x memb []) = False" |
471 | m2: "(x memb (y#xs)) = ((x=y) \<or> (x memb xs))" |
532 | m2: "(x memb (y#xs)) = ((x=y) \<or> (x memb xs))" |
472 |
533 |
|
534 lemma mem_respects: |
|
535 fixes z::"nat" |
|
536 assumes a: "list_eq x y" |
|
537 shows "z memb x = z memb y" |
|
538 using a |
|
539 apply(induct) |
|
540 apply(auto) |
|
541 done |
|
542 |
473 |
543 |
474 local_setup {* |
544 local_setup {* |
475 make_const_def "IN" @{term "membship"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd |
545 make_const_def "IN" @{term "membship"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd |
476 *} |
546 *} |
477 |
547 |
478 term membship |
548 term membship |
479 term IN |
549 term IN |
|
550 thm IN_def |
|
551 |
|
552 lemmas a = QUOT_TYPE.ABS_def[OF QUOT_TYPE_fset] |
|
553 thm QUOT_TYPE.thm11[OF QUOT_TYPE_fset, THEN iffD1, simplified a] |
|
554 |
|
555 lemma yy: |
|
556 shows "(False = x memb []) = (False = IN (x::nat) EMPTY)" |
|
557 unfolding IN_def EMPTY_def |
|
558 apply(rule_tac f="(op =) False" in arg_cong) |
|
559 apply(rule mem_respects) |
|
560 apply(unfold REP_fset_def ABS_fset_def) |
|
561 apply(rule QUOT_TYPE.REP_ABS_rsp[OF QUOT_TYPE_fset]) |
|
562 apply(rule list_eq.intros) |
|
563 done |
480 |
564 |
481 lemma |
565 lemma |
482 shows "IN x EMPTY = False" |
566 shows "IN (x::nat) EMPTY = False" |
483 unfolding IN_def EMPTY_def |
567 using m1 |
484 apply(auto) |
568 apply - |
485 thm Rep_fset_inverse |
569 apply(rule yy[THEN iffD1, symmetric]) |
486 |
570 apply(simp) |
487 |
571 done |
488 |
572 |
489 |
573 lemma |
490 |
574 shows "((x=y) \<or> (IN x xs) = (IN (x::nat) (INSERT y xs))) = |
491 |
575 ((x = y) \<or> x memb REP_fset xs = x memb (y # REP_fset xs))" |
492 |
576 unfolding IN_def INSERT_def |
493 |
577 apply(rule_tac f="(op \<or>) (x=y)" in arg_cong) |
494 |
578 apply(rule_tac f="(op =) (x memb REP_fset xs)" in arg_cong) |
495 |
579 apply(rule mem_respects) |
496 text {* old stuff *} |
580 apply(rule list_eq.intros(3)) |
497 |
581 apply(unfold REP_fset_def ABS_fset_def) |
498 |
582 apply(rule QUOT_TYPE.REP_ABS_rsp[OF QUOT_TYPE_fset]) |
499 lemma QUOT_TYPE_qtrm_old: |
583 apply(rule list_eq_sym) |
500 "QUOT_TYPE R Abs_qtrm Rep_qtrm" |
584 done |
501 apply(rule QUOT_TYPE.intro) |
585 |
502 apply(rule r_eq) |
|
503 apply(rule Rep_qtrm[simplified mem_def]) |
|
504 apply(rule Rep_qtrm_inverse) |
|
505 apply(rule Abs_qtrm_inverse[simplified mem_def]) |
|
506 apply(rule exI) |
|
507 apply(rule refl) |
|
508 apply(rule Rep_qtrm_inject) |
|
509 done |
|
510 |
|
511 definition |
|
512 "ABS_qtrm_old \<equiv> QUOT_TYPE.ABS R Abs_qtrm" |
|
513 |
|
514 definition |
|
515 "REP_qtrm_old \<equiv> QUOT_TYPE.REP Rep_qtrm" |
|
516 |
|
517 lemma |
|
518 "QUOTIENT R (ABS_qtrm) (REP_qtrm)" |
|
519 apply(simp add: ABS_qtrm_def REP_qtrm_def) |
|
520 apply(rule QUOT_TYPE.QUOTIENT) |
|
521 apply(rule QUOT_TYPE_qtrm) |
|
522 done |
|
523 |
|
524 term "var" |
|
525 term "app" |
|
526 term "lam" |
|
527 |
|
528 definition |
|
529 "VAR x \<equiv> ABS_qtrm (var x)" |
|
530 |
|
531 definition |
|
532 "APP t1 t2 \<equiv> ABS_qtrm (app (REP_qtrm t1) (REP_qtrm t2))" |
|
533 |
|
534 definition |
|
535 "LAM x t \<equiv> ABS_qtrm (lam x (REP_qtrm t))" |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 definition |
|
541 "VR x \<equiv> ABS_qt (vr x)" |
|
542 |
|
543 definition |
|
544 "AP ts \<equiv> ABS_qt (ap (map REP_qt ts))" |
|
545 |
|
546 definition |
|
547 "LM x t \<equiv> ABS_qt (lm x (REP_qt t))" |
|
548 |
|
549 (* for printing types *) |
|
550 ML {* |
|
551 fun setmp_show_all_types f = |
|
552 setmp show_all_types |
|
553 (! show_types orelse ! show_sorts orelse ! show_all_types) f |
|
554 *} |
|