src/HOL/Typedef.thy
 author wenzelm Mon Mar 16 18:24:30 2009 +0100 (2009-03-16) changeset 30549 d2d7874648bd parent 29797 08ef36ed2f8a child 31723 f5cafe803b55 permissions -rw-r--r--
simplified method setup;
 wenzelm@11608 ` 1` ```(* Title: HOL/Typedef.thy ``` wenzelm@11608 ` 2` ``` Author: Markus Wenzel, TU Munich ``` wenzelm@11743 ` 3` ```*) ``` wenzelm@11608 ` 4` wenzelm@11979 ` 5` ```header {* HOL type definitions *} ``` wenzelm@11608 ` 6` nipkow@15131 ` 7` ```theory Typedef ``` nipkow@15140 ` 8` ```imports Set ``` haftmann@20426 ` 9` ```uses ``` haftmann@20426 ` 10` ``` ("Tools/typedef_package.ML") ``` haftmann@20426 ` 11` ``` ("Tools/typecopy_package.ML") ``` haftmann@20426 ` 12` ``` ("Tools/typedef_codegen.ML") ``` nipkow@15131 ` 13` ```begin ``` wenzelm@11608 ` 14` haftmann@23247 ` 15` ```ML {* ``` haftmann@23247 ` 16` ```structure HOL = struct val thy = theory "HOL" end; ``` haftmann@23247 ` 17` ```*} -- "belongs to theory HOL" ``` haftmann@23247 ` 18` wenzelm@13412 ` 19` ```locale type_definition = ``` wenzelm@13412 ` 20` ``` fixes Rep and Abs and A ``` wenzelm@13412 ` 21` ``` assumes Rep: "Rep x \ A" ``` wenzelm@13412 ` 22` ``` and Rep_inverse: "Abs (Rep x) = x" ``` wenzelm@13412 ` 23` ``` and Abs_inverse: "y \ A ==> Rep (Abs y) = y" ``` wenzelm@13412 ` 24` ``` -- {* This will be axiomatized for each typedef! *} ``` haftmann@23247 ` 25` ```begin ``` wenzelm@11608 ` 26` haftmann@23247 ` 27` ```lemma Rep_inject: ``` wenzelm@13412 ` 28` ``` "(Rep x = Rep y) = (x = y)" ``` wenzelm@13412 ` 29` ```proof ``` wenzelm@13412 ` 30` ``` assume "Rep x = Rep y" ``` haftmann@23710 ` 31` ``` then have "Abs (Rep x) = Abs (Rep y)" by (simp only:) ``` haftmann@23710 ` 32` ``` moreover have "Abs (Rep x) = x" by (rule Rep_inverse) ``` haftmann@23710 ` 33` ``` moreover have "Abs (Rep y) = y" by (rule Rep_inverse) ``` haftmann@23710 ` 34` ``` ultimately show "x = y" by simp ``` wenzelm@13412 ` 35` ```next ``` wenzelm@13412 ` 36` ``` assume "x = y" ``` wenzelm@13412 ` 37` ``` thus "Rep x = Rep y" by (simp only:) ``` wenzelm@13412 ` 38` ```qed ``` wenzelm@11608 ` 39` haftmann@23247 ` 40` ```lemma Abs_inject: ``` wenzelm@13412 ` 41` ``` assumes x: "x \ A" and y: "y \ A" ``` wenzelm@13412 ` 42` ``` shows "(Abs x = Abs y) = (x = y)" ``` wenzelm@13412 ` 43` ```proof ``` wenzelm@13412 ` 44` ``` assume "Abs x = Abs y" ``` haftmann@23710 ` 45` ``` then have "Rep (Abs x) = Rep (Abs y)" by (simp only:) ``` haftmann@23710 ` 46` ``` moreover from x have "Rep (Abs x) = x" by (rule Abs_inverse) ``` haftmann@23710 ` 47` ``` moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse) ``` haftmann@23710 ` 48` ``` ultimately show "x = y" by simp ``` wenzelm@13412 ` 49` ```next ``` wenzelm@13412 ` 50` ``` assume "x = y" ``` wenzelm@13412 ` 51` ``` thus "Abs x = Abs y" by (simp only:) ``` wenzelm@11608 ` 52` ```qed ``` wenzelm@11608 ` 53` haftmann@23247 ` 54` ```lemma Rep_cases [cases set]: ``` wenzelm@13412 ` 55` ``` assumes y: "y \ A" ``` wenzelm@13412 ` 56` ``` and hyp: "!!x. y = Rep x ==> P" ``` wenzelm@13412 ` 57` ``` shows P ``` wenzelm@13412 ` 58` ```proof (rule hyp) ``` wenzelm@13412 ` 59` ``` from y have "Rep (Abs y) = y" by (rule Abs_inverse) ``` wenzelm@13412 ` 60` ``` thus "y = Rep (Abs y)" .. ``` wenzelm@11608 ` 61` ```qed ``` wenzelm@11608 ` 62` haftmann@23247 ` 63` ```lemma Abs_cases [cases type]: ``` wenzelm@13412 ` 64` ``` assumes r: "!!y. x = Abs y ==> y \ A ==> P" ``` wenzelm@13412 ` 65` ``` shows P ``` wenzelm@13412 ` 66` ```proof (rule r) ``` wenzelm@13412 ` 67` ``` have "Abs (Rep x) = x" by (rule Rep_inverse) ``` wenzelm@13412 ` 68` ``` thus "x = Abs (Rep x)" .. ``` wenzelm@13412 ` 69` ``` show "Rep x \ A" by (rule Rep) ``` wenzelm@11608 ` 70` ```qed ``` wenzelm@11608 ` 71` haftmann@23247 ` 72` ```lemma Rep_induct [induct set]: ``` wenzelm@13412 ` 73` ``` assumes y: "y \ A" ``` wenzelm@13412 ` 74` ``` and hyp: "!!x. P (Rep x)" ``` wenzelm@13412 ` 75` ``` shows "P y" ``` wenzelm@11608 ` 76` ```proof - ``` wenzelm@13412 ` 77` ``` have "P (Rep (Abs y))" by (rule hyp) ``` haftmann@23710 ` 78` ``` moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse) ``` haftmann@23710 ` 79` ``` ultimately show "P y" by simp ``` wenzelm@11608 ` 80` ```qed ``` wenzelm@11608 ` 81` haftmann@23247 ` 82` ```lemma Abs_induct [induct type]: ``` wenzelm@13412 ` 83` ``` assumes r: "!!y. y \ A ==> P (Abs y)" ``` wenzelm@13412 ` 84` ``` shows "P x" ``` wenzelm@11608 ` 85` ```proof - ``` wenzelm@13412 ` 86` ``` have "Rep x \ A" by (rule Rep) ``` haftmann@23710 ` 87` ``` then have "P (Abs (Rep x))" by (rule r) ``` haftmann@23710 ` 88` ``` moreover have "Abs (Rep x) = x" by (rule Rep_inverse) ``` haftmann@23710 ` 89` ``` ultimately show "P x" by simp ``` wenzelm@11608 ` 90` ```qed ``` wenzelm@11608 ` 91` huffman@27295 ` 92` ```lemma Rep_range: "range Rep = A" ``` huffman@24269 ` 93` ```proof ``` huffman@24269 ` 94` ``` show "range Rep <= A" using Rep by (auto simp add: image_def) ``` huffman@24269 ` 95` ``` show "A <= range Rep" ``` nipkow@23433 ` 96` ``` proof ``` nipkow@23433 ` 97` ``` fix x assume "x : A" ``` huffman@24269 ` 98` ``` hence "x = Rep (Abs x)" by (rule Abs_inverse [symmetric]) ``` huffman@24269 ` 99` ``` thus "x : range Rep" by (rule range_eqI) ``` nipkow@23433 ` 100` ``` qed ``` nipkow@23433 ` 101` ```qed ``` nipkow@23433 ` 102` huffman@27295 ` 103` ```lemma Abs_image: "Abs ` A = UNIV" ``` huffman@27295 ` 104` ```proof ``` huffman@27295 ` 105` ``` show "Abs ` A <= UNIV" by (rule subset_UNIV) ``` huffman@27295 ` 106` ```next ``` huffman@27295 ` 107` ``` show "UNIV <= Abs ` A" ``` huffman@27295 ` 108` ``` proof ``` huffman@27295 ` 109` ``` fix x ``` huffman@27295 ` 110` ``` have "x = Abs (Rep x)" by (rule Rep_inverse [symmetric]) ``` huffman@27295 ` 111` ``` moreover have "Rep x : A" by (rule Rep) ``` huffman@27295 ` 112` ``` ultimately show "x : Abs ` A" by (rule image_eqI) ``` huffman@27295 ` 113` ``` qed ``` huffman@27295 ` 114` ```qed ``` huffman@27295 ` 115` haftmann@23247 ` 116` ```end ``` haftmann@23247 ` 117` wenzelm@29056 ` 118` ```use "Tools/typedef_package.ML" setup TypedefPackage.setup ``` wenzelm@29056 ` 119` ```use "Tools/typecopy_package.ML" setup TypecopyPackage.setup ``` wenzelm@29056 ` 120` ```use "Tools/typedef_codegen.ML" setup TypedefCodegen.setup ``` wenzelm@11608 ` 121` wenzelm@11608 ` 122` ```end ```