src/HOL/Enum.thy
changeset 70523 1182ea5c9a6e
parent 69850 5f993636ac07
child 71154 7db80bd16f1c
equal deleted inserted replaced
70522:f2d58cafbc13 70523:1182ea5c9a6e
   694 definition "x mod y = (case (x, y) of (a\<^sub>2, a\<^sub>1) \<Rightarrow> a\<^sub>2 | _ \<Rightarrow> a\<^sub>1)"
   694 definition "x mod y = (case (x, y) of (a\<^sub>2, a\<^sub>1) \<Rightarrow> a\<^sub>2 | _ \<Rightarrow> a\<^sub>1)"
   695 definition "abs = (\<lambda>x :: finite_2. x)"
   695 definition "abs = (\<lambda>x :: finite_2. x)"
   696 definition "sgn = (\<lambda>x :: finite_2. x)"
   696 definition "sgn = (\<lambda>x :: finite_2. x)"
   697 instance
   697 instance
   698   by standard
   698   by standard
   699     (simp_all add: plus_finite_2_def uminus_finite_2_def minus_finite_2_def
   699     (subproofs
   700       times_finite_2_def
   700       \<open>simp_all add: plus_finite_2_def uminus_finite_2_def minus_finite_2_def
   701       inverse_finite_2_def divide_finite_2_def modulo_finite_2_def
   701         times_finite_2_def
   702       abs_finite_2_def sgn_finite_2_def
   702         inverse_finite_2_def divide_finite_2_def modulo_finite_2_def
   703       split: finite_2.splits)
   703         abs_finite_2_def sgn_finite_2_def
       
   704         split: finite_2.splits\<close>)
   704 end
   705 end
   705 
   706 
   706 lemma two_finite_2 [simp]:
   707 lemma two_finite_2 [simp]:
   707   "2 = a\<^sub>1"
   708   "2 = a\<^sub>1"
   708   by (simp add: numeral.simps plus_finite_2_def)
   709   by (simp add: numeral.simps plus_finite_2_def)
   716 definition [simp]: "unit_factor = (id :: finite_2 \<Rightarrow> _)"
   717 definition [simp]: "unit_factor = (id :: finite_2 \<Rightarrow> _)"
   717 definition [simp]: "euclidean_size x = (case x of a\<^sub>1 \<Rightarrow> 0 | a\<^sub>2 \<Rightarrow> 1)"
   718 definition [simp]: "euclidean_size x = (case x of a\<^sub>1 \<Rightarrow> 0 | a\<^sub>2 \<Rightarrow> 1)"
   718 definition [simp]: "division_segment (x :: finite_2) = 1"
   719 definition [simp]: "division_segment (x :: finite_2) = 1"
   719 instance
   720 instance
   720   by standard
   721   by standard
   721     (auto simp add: divide_finite_2_def times_finite_2_def dvd_finite_2_unfold
   722     (subproofs
   722     split: finite_2.splits)
   723       \<open>auto simp add: divide_finite_2_def times_finite_2_def dvd_finite_2_unfold
       
   724         split: finite_2.splits\<close>)
   723 end
   725 end
   724 
   726 
   725  
   727  
   726 hide_const (open) a\<^sub>1 a\<^sub>2
   728 hide_const (open) a\<^sub>1 a\<^sub>2
   727 
   729 
   928 definition "x mod y = (case y of a\<^sub>1 \<Rightarrow> x | _ \<Rightarrow> a\<^sub>1)"
   930 definition "x mod y = (case y of a\<^sub>1 \<Rightarrow> x | _ \<Rightarrow> a\<^sub>1)"
   929 definition "abs = (\<lambda>x. case x of a\<^sub>3 \<Rightarrow> a\<^sub>2 | _ \<Rightarrow> x)"
   931 definition "abs = (\<lambda>x. case x of a\<^sub>3 \<Rightarrow> a\<^sub>2 | _ \<Rightarrow> x)"
   930 definition "sgn = (\<lambda>x :: finite_3. x)"
   932 definition "sgn = (\<lambda>x :: finite_3. x)"
   931 instance
   933 instance
   932   by standard
   934   by standard
   933     (simp_all add: plus_finite_3_def uminus_finite_3_def minus_finite_3_def
   935     (subproofs
   934       times_finite_3_def
   936       \<open>simp_all add: plus_finite_3_def uminus_finite_3_def minus_finite_3_def
   935       inverse_finite_3_def divide_finite_3_def modulo_finite_3_def
   937         times_finite_3_def
   936       abs_finite_3_def sgn_finite_3_def
   938         inverse_finite_3_def divide_finite_3_def modulo_finite_3_def
   937       less_finite_3_def
   939         abs_finite_3_def sgn_finite_3_def
   938       split: finite_3.splits)
   940         less_finite_3_def
       
   941         split: finite_3.splits\<close>)
   939 end
   942 end
   940 
   943 
   941 lemma two_finite_3 [simp]:
   944 lemma two_finite_3 [simp]:
   942   "2 = a\<^sub>3"
   945   "2 = a\<^sub>3"
   943   by (simp add: numeral.simps plus_finite_3_def)
   946   by (simp add: numeral.simps plus_finite_3_def)
   949 instantiation finite_3 :: "{normalization_semidom, unique_euclidean_semiring}" begin
   952 instantiation finite_3 :: "{normalization_semidom, unique_euclidean_semiring}" begin
   950 definition [simp]: "normalize x = (case x of a\<^sub>3 \<Rightarrow> a\<^sub>2 | _ \<Rightarrow> x)"
   953 definition [simp]: "normalize x = (case x of a\<^sub>3 \<Rightarrow> a\<^sub>2 | _ \<Rightarrow> x)"
   951 definition [simp]: "unit_factor = (id :: finite_3 \<Rightarrow> _)"
   954 definition [simp]: "unit_factor = (id :: finite_3 \<Rightarrow> _)"
   952 definition [simp]: "euclidean_size x = (case x of a\<^sub>1 \<Rightarrow> 0 | _ \<Rightarrow> 1)"
   955 definition [simp]: "euclidean_size x = (case x of a\<^sub>1 \<Rightarrow> 0 | _ \<Rightarrow> 1)"
   953 definition [simp]: "division_segment (x :: finite_3) = 1"
   956 definition [simp]: "division_segment (x :: finite_3) = 1"
   954 instance proof
   957 instance
       
   958 proof
   955   fix x :: finite_3
   959   fix x :: finite_3
   956   assume "x \<noteq> 0"
   960   assume "x \<noteq> 0"
   957   then show "is_unit (unit_factor x)"
   961   then show "is_unit (unit_factor x)"
   958     by (cases x) (simp_all add: dvd_finite_3_unfold)
   962     by (cases x) (simp_all add: dvd_finite_3_unfold)
   959 qed (auto simp add: divide_finite_3_def times_finite_3_def
   963 qed
   960   dvd_finite_3_unfold inverse_finite_3_def plus_finite_3_def
   964   (subproofs
   961   split: finite_3.splits)
   965     \<open>auto simp add: divide_finite_3_def times_finite_3_def
       
   966       dvd_finite_3_unfold inverse_finite_3_def plus_finite_3_def
       
   967       split: finite_3.splits\<close>)
   962 end
   968 end
   963 
   969 
   964 hide_const (open) a\<^sub>1 a\<^sub>2 a\<^sub>3
   970 hide_const (open) a\<^sub>1 a\<^sub>2 a\<^sub>3
   965 
   971 
   966 datatype (plugins only: code "quickcheck" extraction) finite_4 =
   972 datatype (plugins only: code "quickcheck" extraction) finite_4 =
  1027      (a\<^sub>4, _) \<Rightarrow> a\<^sub>4 | (_, a\<^sub>4) \<Rightarrow> a\<^sub>4 | (a\<^sub>2, a\<^sub>3) \<Rightarrow> a\<^sub>4 | (a\<^sub>3, a\<^sub>2) \<Rightarrow> a\<^sub>4
  1033      (a\<^sub>4, _) \<Rightarrow> a\<^sub>4 | (_, a\<^sub>4) \<Rightarrow> a\<^sub>4 | (a\<^sub>2, a\<^sub>3) \<Rightarrow> a\<^sub>4 | (a\<^sub>3, a\<^sub>2) \<Rightarrow> a\<^sub>4
  1028   | (a\<^sub>2, _) \<Rightarrow> a\<^sub>2 | (_, a\<^sub>2) \<Rightarrow> a\<^sub>2
  1034   | (a\<^sub>2, _) \<Rightarrow> a\<^sub>2 | (_, a\<^sub>2) \<Rightarrow> a\<^sub>2
  1029   | (a\<^sub>3, _) \<Rightarrow> a\<^sub>3 | (_, a\<^sub>3) \<Rightarrow> a\<^sub>3
  1035   | (a\<^sub>3, _) \<Rightarrow> a\<^sub>3 | (_, a\<^sub>3) \<Rightarrow> a\<^sub>3
  1030   | _ \<Rightarrow> a\<^sub>1)"
  1036   | _ \<Rightarrow> a\<^sub>1)"
  1031 
  1037 
  1032 instance proof
  1038 instance
  1033 qed(auto simp add: less_finite_4_def less_eq_finite_4_def Inf_finite_4_def Sup_finite_4_def 
  1039   by standard
  1034     inf_finite_4_def sup_finite_4_def split: finite_4.splits)
  1040     (subproofs
       
  1041       \<open>auto simp add: less_finite_4_def less_eq_finite_4_def Inf_finite_4_def Sup_finite_4_def 
       
  1042         inf_finite_4_def sup_finite_4_def split: finite_4.splits\<close>)
  1035 end
  1043 end
  1036 
  1044 
  1037 instance finite_4 :: complete_lattice ..
  1045 instance finite_4 :: complete_lattice ..
  1038 
  1046 
  1039 instance finite_4 :: complete_distrib_lattice ..
  1047 instance finite_4 :: complete_distrib_lattice ..
  1040 
  1048 
  1041 instantiation finite_4 :: complete_boolean_algebra begin
  1049 instantiation finite_4 :: complete_boolean_algebra begin
  1042 definition "- x = (case x of a\<^sub>1 \<Rightarrow> a\<^sub>4 | a\<^sub>2 \<Rightarrow> a\<^sub>3 | a\<^sub>3 \<Rightarrow> a\<^sub>2 | a\<^sub>4 \<Rightarrow> a\<^sub>1)"
  1050 definition "- x = (case x of a\<^sub>1 \<Rightarrow> a\<^sub>4 | a\<^sub>2 \<Rightarrow> a\<^sub>3 | a\<^sub>3 \<Rightarrow> a\<^sub>2 | a\<^sub>4 \<Rightarrow> a\<^sub>1)"
  1043 definition "x - y = x \<sqinter> - (y :: finite_4)"
  1051 definition "x - y = x \<sqinter> - (y :: finite_4)"
  1044 instance
  1052 instance
  1045 by intro_classes
  1053   by standard
  1046   (simp_all add: inf_finite_4_def sup_finite_4_def uminus_finite_4_def minus_finite_4_def 
  1054     (subproofs
  1047     split: finite_4.splits)
  1055       \<open>simp_all add: inf_finite_4_def sup_finite_4_def uminus_finite_4_def minus_finite_4_def 
       
  1056         split: finite_4.splits\<close>)
  1048 end
  1057 end
  1049 
  1058 
  1050 hide_const (open) a\<^sub>1 a\<^sub>2 a\<^sub>3 a\<^sub>4
  1059 hide_const (open) a\<^sub>1 a\<^sub>2 a\<^sub>3 a\<^sub>4
  1051 
  1060 
  1052 datatype (plugins only: code "quickcheck" extraction) finite_5 =
  1061 datatype (plugins only: code "quickcheck" extraction) finite_5 =
  1128    | (a\<^sub>3, _) \<Rightarrow> a\<^sub>3 | (_, a\<^sub>3) \<Rightarrow> a\<^sub>3
  1137    | (a\<^sub>3, _) \<Rightarrow> a\<^sub>3 | (_, a\<^sub>3) \<Rightarrow> a\<^sub>3
  1129    | (a\<^sub>2, _) \<Rightarrow> a\<^sub>2 | (_, a\<^sub>2) \<Rightarrow> a\<^sub>2
  1138    | (a\<^sub>2, _) \<Rightarrow> a\<^sub>2 | (_, a\<^sub>2) \<Rightarrow> a\<^sub>2
  1130    | (a\<^sub>4, _) \<Rightarrow> a\<^sub>4 | (_, a\<^sub>4) \<Rightarrow> a\<^sub>4
  1139    | (a\<^sub>4, _) \<Rightarrow> a\<^sub>4 | (_, a\<^sub>4) \<Rightarrow> a\<^sub>4
  1131    | _ \<Rightarrow> a\<^sub>1)"
  1140    | _ \<Rightarrow> a\<^sub>1)"
  1132 
  1141 
  1133 instance 
  1142 instance
  1134 proof
  1143   by standard
  1135 qed (auto simp add: less_eq_finite_5_def less_finite_5_def inf_finite_5_def sup_finite_5_def 
  1144     (subproofs
  1136     Inf_finite_5_def Sup_finite_5_def split: finite_5.splits if_split_asm)
  1145       \<open>auto simp add: less_eq_finite_5_def less_finite_5_def inf_finite_5_def sup_finite_5_def 
       
  1146         Inf_finite_5_def Sup_finite_5_def split: finite_5.splits if_split_asm\<close>)
  1137 end
  1147 end
  1138 
  1148 
  1139 
  1149 
  1140 instance  finite_5 :: complete_lattice ..
  1150 instance  finite_5 :: complete_lattice ..
  1141 
  1151