src/HOL/Typedef.thy
 author haftmann Mon Nov 29 13:44:54 2010 +0100 (2010-11-29) changeset 40815 6e2d17cc0d1d parent 38536 7e57a0dcbd4f child 41732 996b0c14a430 permissions -rw-r--r--
equivI has replaced equiv.intro
 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@38536 ` 9` ```uses ("Tools/typedef.ML") ``` nipkow@15131 ` 10` ```begin ``` wenzelm@11608 ` 11` haftmann@23247 ` 12` ```ML {* ``` wenzelm@37863 ` 13` ```structure HOL = struct val thy = @{theory HOL} end; ``` haftmann@23247 ` 14` ```*} -- "belongs to theory HOL" ``` haftmann@23247 ` 15` wenzelm@13412 ` 16` ```locale type_definition = ``` wenzelm@13412 ` 17` ``` fixes Rep and Abs and A ``` wenzelm@13412 ` 18` ``` assumes Rep: "Rep x \ A" ``` wenzelm@13412 ` 19` ``` and Rep_inverse: "Abs (Rep x) = x" ``` wenzelm@13412 ` 20` ``` and Abs_inverse: "y \ A ==> Rep (Abs y) = y" ``` wenzelm@13412 ` 21` ``` -- {* This will be axiomatized for each typedef! *} ``` haftmann@23247 ` 22` ```begin ``` wenzelm@11608 ` 23` haftmann@23247 ` 24` ```lemma Rep_inject: ``` wenzelm@13412 ` 25` ``` "(Rep x = Rep y) = (x = y)" ``` wenzelm@13412 ` 26` ```proof ``` wenzelm@13412 ` 27` ``` assume "Rep x = Rep y" ``` haftmann@23710 ` 28` ``` then have "Abs (Rep x) = Abs (Rep y)" by (simp only:) ``` haftmann@23710 ` 29` ``` moreover have "Abs (Rep x) = x" by (rule Rep_inverse) ``` haftmann@23710 ` 30` ``` moreover have "Abs (Rep y) = y" by (rule Rep_inverse) ``` haftmann@23710 ` 31` ``` ultimately show "x = y" by simp ``` wenzelm@13412 ` 32` ```next ``` wenzelm@13412 ` 33` ``` assume "x = y" ``` wenzelm@13412 ` 34` ``` thus "Rep x = Rep y" by (simp only:) ``` wenzelm@13412 ` 35` ```qed ``` wenzelm@11608 ` 36` haftmann@23247 ` 37` ```lemma Abs_inject: ``` wenzelm@13412 ` 38` ``` assumes x: "x \ A" and y: "y \ A" ``` wenzelm@13412 ` 39` ``` shows "(Abs x = Abs y) = (x = y)" ``` wenzelm@13412 ` 40` ```proof ``` wenzelm@13412 ` 41` ``` assume "Abs x = Abs y" ``` haftmann@23710 ` 42` ``` then have "Rep (Abs x) = Rep (Abs y)" by (simp only:) ``` haftmann@23710 ` 43` ``` moreover from x have "Rep (Abs x) = x" by (rule Abs_inverse) ``` haftmann@23710 ` 44` ``` moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse) ``` haftmann@23710 ` 45` ``` ultimately show "x = y" by simp ``` wenzelm@13412 ` 46` ```next ``` wenzelm@13412 ` 47` ``` assume "x = y" ``` wenzelm@13412 ` 48` ``` thus "Abs x = Abs y" by (simp only:) ``` wenzelm@11608 ` 49` ```qed ``` wenzelm@11608 ` 50` haftmann@23247 ` 51` ```lemma Rep_cases [cases set]: ``` wenzelm@13412 ` 52` ``` assumes y: "y \ A" ``` wenzelm@13412 ` 53` ``` and hyp: "!!x. y = Rep x ==> P" ``` wenzelm@13412 ` 54` ``` shows P ``` wenzelm@13412 ` 55` ```proof (rule hyp) ``` wenzelm@13412 ` 56` ``` from y have "Rep (Abs y) = y" by (rule Abs_inverse) ``` wenzelm@13412 ` 57` ``` thus "y = Rep (Abs y)" .. ``` wenzelm@11608 ` 58` ```qed ``` wenzelm@11608 ` 59` haftmann@23247 ` 60` ```lemma Abs_cases [cases type]: ``` wenzelm@13412 ` 61` ``` assumes r: "!!y. x = Abs y ==> y \ A ==> P" ``` wenzelm@13412 ` 62` ``` shows P ``` wenzelm@13412 ` 63` ```proof (rule r) ``` wenzelm@13412 ` 64` ``` have "Abs (Rep x) = x" by (rule Rep_inverse) ``` wenzelm@13412 ` 65` ``` thus "x = Abs (Rep x)" .. ``` wenzelm@13412 ` 66` ``` show "Rep x \ A" by (rule Rep) ``` wenzelm@11608 ` 67` ```qed ``` wenzelm@11608 ` 68` haftmann@23247 ` 69` ```lemma Rep_induct [induct set]: ``` wenzelm@13412 ` 70` ``` assumes y: "y \ A" ``` wenzelm@13412 ` 71` ``` and hyp: "!!x. P (Rep x)" ``` wenzelm@13412 ` 72` ``` shows "P y" ``` wenzelm@11608 ` 73` ```proof - ``` wenzelm@13412 ` 74` ``` have "P (Rep (Abs y))" by (rule hyp) ``` haftmann@23710 ` 75` ``` moreover from y have "Rep (Abs y) = y" by (rule Abs_inverse) ``` haftmann@23710 ` 76` ``` ultimately show "P y" by simp ``` wenzelm@11608 ` 77` ```qed ``` wenzelm@11608 ` 78` haftmann@23247 ` 79` ```lemma Abs_induct [induct type]: ``` wenzelm@13412 ` 80` ``` assumes r: "!!y. y \ A ==> P (Abs y)" ``` wenzelm@13412 ` 81` ``` shows "P x" ``` wenzelm@11608 ` 82` ```proof - ``` wenzelm@13412 ` 83` ``` have "Rep x \ A" by (rule Rep) ``` haftmann@23710 ` 84` ``` then have "P (Abs (Rep x))" by (rule r) ``` haftmann@23710 ` 85` ``` moreover have "Abs (Rep x) = x" by (rule Rep_inverse) ``` haftmann@23710 ` 86` ``` ultimately show "P x" by simp ``` wenzelm@11608 ` 87` ```qed ``` wenzelm@11608 ` 88` huffman@27295 ` 89` ```lemma Rep_range: "range Rep = A" ``` huffman@24269 ` 90` ```proof ``` huffman@24269 ` 91` ``` show "range Rep <= A" using Rep by (auto simp add: image_def) ``` huffman@24269 ` 92` ``` show "A <= range Rep" ``` nipkow@23433 ` 93` ``` proof ``` nipkow@23433 ` 94` ``` fix x assume "x : A" ``` huffman@24269 ` 95` ``` hence "x = Rep (Abs x)" by (rule Abs_inverse [symmetric]) ``` huffman@24269 ` 96` ``` thus "x : range Rep" by (rule range_eqI) ``` nipkow@23433 ` 97` ``` qed ``` nipkow@23433 ` 98` ```qed ``` nipkow@23433 ` 99` huffman@27295 ` 100` ```lemma Abs_image: "Abs ` A = UNIV" ``` huffman@27295 ` 101` ```proof ``` huffman@27295 ` 102` ``` show "Abs ` A <= UNIV" by (rule subset_UNIV) ``` huffman@27295 ` 103` ```next ``` huffman@27295 ` 104` ``` show "UNIV <= Abs ` A" ``` huffman@27295 ` 105` ``` proof ``` huffman@27295 ` 106` ``` fix x ``` huffman@27295 ` 107` ``` have "x = Abs (Rep x)" by (rule Rep_inverse [symmetric]) ``` huffman@27295 ` 108` ``` moreover have "Rep x : A" by (rule Rep) ``` huffman@27295 ` 109` ``` ultimately show "x : Abs ` A" by (rule image_eqI) ``` huffman@27295 ` 110` ``` qed ``` huffman@27295 ` 111` ```qed ``` huffman@27295 ` 112` haftmann@23247 ` 113` ```end ``` haftmann@23247 ` 114` haftmann@31723 ` 115` ```use "Tools/typedef.ML" setup Typedef.setup ``` wenzelm@11608 ` 116` wenzelm@11608 ` 117` ```end ```