src/HOL/Library/Numeral_Type.thy
changeset 69661 a03a63b81f44
parent 69593 3dda49e08b9d
child 69663 41ff40bf1530
child 69677 a06b204527e6
equal deleted inserted replaced
69660:2bc2a8599369 69661:a03a63b81f44
   406 instantiation bit0 :: (finite) enum begin
   406 instantiation bit0 :: (finite) enum begin
   407 definition "(enum_class.enum :: 'a bit0 list) = map (Abs_bit0' \<circ> int) (upt 0 (CARD('a bit0)))"
   407 definition "(enum_class.enum :: 'a bit0 list) = map (Abs_bit0' \<circ> int) (upt 0 (CARD('a bit0)))"
   408 definition "enum_class.enum_all P = (\<forall>b :: 'a bit0 \<in> set enum_class.enum. P b)"
   408 definition "enum_class.enum_all P = (\<forall>b :: 'a bit0 \<in> set enum_class.enum. P b)"
   409 definition "enum_class.enum_ex P = (\<exists>b :: 'a bit0 \<in> set enum_class.enum. P b)"
   409 definition "enum_class.enum_ex P = (\<exists>b :: 'a bit0 \<in> set enum_class.enum. P b)"
   410 
   410 
   411 instance
   411 instance proof
   412 proof(intro_classes)
       
   413   show "distinct (enum_class.enum :: 'a bit0 list)"
   412   show "distinct (enum_class.enum :: 'a bit0 list)"
   414     by (simp add: enum_bit0_def distinct_map inj_on_def Abs_bit0'_def Abs_bit0_inject)
   413     by (simp add: enum_bit0_def distinct_map inj_on_def Abs_bit0'_def Abs_bit0_inject)
   415 
   414 
   416   show univ_eq: "(UNIV :: 'a bit0 set) = set enum_class.enum"
   415   let ?Abs = "Abs_bit0 :: _ \<Rightarrow> 'a bit0"
   417     unfolding enum_bit0_def type_definition.Abs_image[OF type_definition_bit0, symmetric]
   416   interpret type_definition Rep_bit0 ?Abs "{0..<2 * int CARD('a)}"
   418     by (simp add: image_comp [symmetric] inj_on_Abs_bit0 card_image image_int_atLeastLessThan)
   417     by (fact type_definition_bit0)
   419       (auto intro!: image_cong[OF refl] simp add: Abs_bit0'_def)
   418   have "UNIV = ?Abs ` {0..<2 * int CARD('a)}"
       
   419     by (simp add: Abs_image)
       
   420   also have "\<dots> = ?Abs ` (int ` {0..<2 * CARD('a)})"
       
   421     by (simp add: image_int_atLeastLessThan)
       
   422   also have "\<dots> = (?Abs \<circ> int) ` {0..<2 * CARD('a)}"
       
   423     by (simp add: image_image cong: image_cong)
       
   424   also have "\<dots> = set enum_class.enum"
       
   425     by (simp add: enum_bit0_def Abs_bit0'_def cong: image_cong_simp)
       
   426   finally show univ_eq: "(UNIV :: 'a bit0 set) = set enum_class.enum" .
   420 
   427 
   421   fix P :: "'a bit0 \<Rightarrow> bool"
   428   fix P :: "'a bit0 \<Rightarrow> bool"
   422   show "enum_class.enum_all P = Ball UNIV P"
   429   show "enum_class.enum_all P = Ball UNIV P"
   423     and "enum_class.enum_ex P = Bex UNIV P"
   430     and "enum_class.enum_ex P = Bex UNIV P"
   424     by(simp_all add: enum_all_bit0_def enum_ex_bit0_def univ_eq)
   431     by(simp_all add: enum_all_bit0_def enum_ex_bit0_def univ_eq)
   435 proof(intro_classes)
   442 proof(intro_classes)
   436   show "distinct (enum_class.enum :: 'a bit1 list)"
   443   show "distinct (enum_class.enum :: 'a bit1 list)"
   437     by(simp only: Abs_bit1'_def zmod_int[symmetric] enum_bit1_def distinct_map Suc_eq_plus1 card_bit1 o_apply inj_on_def)
   444     by(simp only: Abs_bit1'_def zmod_int[symmetric] enum_bit1_def distinct_map Suc_eq_plus1 card_bit1 o_apply inj_on_def)
   438       (clarsimp simp add: Abs_bit1_inject)
   445       (clarsimp simp add: Abs_bit1_inject)
   439 
   446 
   440   show univ_eq: "(UNIV :: 'a bit1 set) = set enum_class.enum"
   447   let ?Abs = "Abs_bit1 :: _ \<Rightarrow> 'a bit1"
   441     unfolding enum_bit1_def type_definition.Abs_image[OF type_definition_bit1, symmetric]
   448   interpret type_definition Rep_bit1 ?Abs "{0..<1 + 2 * int CARD('a)}"
   442     by(simp add: image_comp [symmetric] inj_on_Abs_bit1 card_image image_int_atLeastLessThan)
   449     by (fact type_definition_bit1)
   443       (auto intro!: image_cong[OF refl] simp add: Abs_bit1'_def)
   450   have "UNIV = ?Abs ` {0..<1 + 2 * int CARD('a)}"
       
   451     by (simp add: Abs_image)
       
   452   also have "\<dots> = ?Abs ` (int ` {0..<1 + 2 * CARD('a)})"
       
   453     by (simp add: image_int_atLeastLessThan)
       
   454   also have "\<dots> = (?Abs \<circ> int) ` {0..<1 + 2 * CARD('a)}"
       
   455     by (simp add: image_image cong: image_cong)
       
   456   finally show univ_eq: "(UNIV :: 'a bit1 set) = set enum_class.enum"
       
   457     by (simp only: enum_bit1_def set_map set_upt) (simp add: Abs_bit1'_def cong: image_cong_simp)
   444 
   458 
   445   fix P :: "'a bit1 \<Rightarrow> bool"
   459   fix P :: "'a bit1 \<Rightarrow> bool"
   446   show "enum_class.enum_all P = Ball UNIV P"
   460   show "enum_class.enum_all P = Ball UNIV P"
   447     and "enum_class.enum_ex P = Bex UNIV P"
   461     and "enum_class.enum_ex P = Bex UNIV P"
   448     by(simp_all add: enum_all_bit1_def enum_ex_bit1_def univ_eq)
   462     by(simp_all add: enum_all_bit1_def enum_ex_bit1_def univ_eq)