src/HOL/Library/Enum.thy
changeset 38857 97775f3e8722
parent 37765 26bdfb7b680b
child 39198 f967a16dfcdd
equal deleted inserted replaced
38856:168dba35ecf3 38857:97775f3e8722
    33 end
    33 end
    34 
    34 
    35 
    35 
    36 subsection {* Equality and order on functions *}
    36 subsection {* Equality and order on functions *}
    37 
    37 
    38 instantiation "fun" :: (enum, eq) eq
    38 instantiation "fun" :: (enum, equal) equal
    39 begin
    39 begin
    40 
    40 
    41 definition
    41 definition
    42   "eq_class.eq f g \<longleftrightarrow> (\<forall>x \<in> set enum. f x = g x)"
    42   "HOL.equal f g \<longleftrightarrow> (\<forall>x \<in> set enum. f x = g x)"
    43 
    43 
    44 instance proof
    44 instance proof
    45 qed (simp_all add: eq_fun_def enum_all expand_fun_eq)
    45 qed (simp_all add: equal_fun_def enum_all expand_fun_eq)
    46 
    46 
    47 end
    47 end
       
    48 
       
    49 lemma [code nbe]:
       
    50   "HOL.equal (f :: _ \<Rightarrow> _) f \<longleftrightarrow> True"
       
    51   by (fact equal_refl)
    48 
    52 
    49 lemma order_fun [code]:
    53 lemma order_fun [code]:
    50   fixes f g :: "'a\<Colon>enum \<Rightarrow> 'b\<Colon>order"
    54   fixes f g :: "'a\<Colon>enum \<Rightarrow> 'b\<Colon>order"
    51   shows "f \<le> g \<longleftrightarrow> list_all (\<lambda>x. f x \<le> g x) enum"
    55   shows "f \<le> g \<longleftrightarrow> list_all (\<lambda>x. f x \<le> g x) enum"
    52     and "f < g \<longleftrightarrow> f \<le> g \<and> list_ex (\<lambda>x. f x \<noteq> g x) enum"
    56     and "f < g \<longleftrightarrow> f \<le> g \<and> list_ex (\<lambda>x. f x \<noteq> g x) enum"
   167       distinct_map distinct_n_lists enum_distinct set_n_lists enum_all)
   171       distinct_map distinct_n_lists enum_distinct set_n_lists enum_all)
   168 qed
   172 qed
   169 
   173 
   170 end
   174 end
   171 
   175 
   172 lemma enum_fun_code [code]: "enum = (let enum_a = (enum \<Colon> 'a\<Colon>{enum, eq} list)
   176 lemma enum_fun_code [code]: "enum = (let enum_a = (enum \<Colon> 'a\<Colon>{enum, equal} list)
   173   in map (\<lambda>ys. the o map_of (zip enum_a ys)) (n_lists (length enum_a) enum))"
   177   in map (\<lambda>ys. the o map_of (zip enum_a ys)) (n_lists (length enum_a) enum))"
   174   by (simp add: enum_fun_def Let_def)
   178   by (simp add: enum_fun_def Let_def)
   175 
   179 
   176 instantiation unit :: enum
   180 instantiation unit :: enum
   177 begin
   181 begin