lemma map_enum: fixes x :: 'a shows"map f enum ! fromEnum x = f x" proof - have"fromEnum x ≤ fromEnum (maxBound :: 'a)" by (rule maxBound_is_bound) thenhave"fromEnum x < length (enum::'a list)" by (simp add: maxBound_less_length) thenhave"map f enum ! fromEnum x = f (enum ! fromEnum x)"by simp also have"x ∈ set enum"by simp thenhave"enum ! fromEnum x = x" by (simp add: fromEnum_def nth_the_index) finally show ?thesis . qed
definition
assocs :: "('a ==> 'b) ==> ('a × 'b) list"where "assocs f ≡ map (λx. (x, f x)) enum"
end
(* For historical naming reasons. *) lemmas enum_bool = enum_bool_def
class enum_alt = fixes enum_alt :: "nat ==> 'a option"
class enumeration_alt = enum_alt + assumes enum_alt_one_bound: "enum_alt x = (None :: 'a option) ==> enum_alt (Suc x) = (None :: 'a option)" assumes enum_alt_surj: "range enum_alt ∪ {None} = UNIV" assumes enum_alt_inj "(enum_alt x :: 'a option) = enum_alt y ==>then show ?thesis by (simp add: toEnum_def fromEnum_def nth_the_index the_index_bounded) begin
lemmanum_alt_inj_2: umesenum_alt x = (enum_alt y :: 'a )" \noteq (None :: 'a option)" shows "x = y" proof- from ass have "(x = y) ∨ omEnum" with a show ?thesis by clarsimp qed
lemmaenum_alt_surj_2: "havein set enum" by simp proof - have"Some \in> range enum_alt ∪
then o qed
end
definition
alt_from_ord enum_bool) where "alt_from_ord L \>ln. if (n < length L) then Some (L ! n) else None"
(*Seemingly redundant, but heavily used elsewhere*) enum_altRightarrow> 'a option lemma handy_if_lemmaen P\> B) by simp enum_alt_one_bound
class enumeration_bothenum assumes enum_alt_rel
lemma the_index_less_lengthnumum byum_alt<>(= y<(enum_alt x = (None :: 'a option
lemma enum_alt_inj_2 defines:a:: list) <>enum" shows "(if x < length e then Some (e ! x) else None) = Some (e ! y) ==>
y < length e ==> x = y" by (simp ad _dfslt fslit_mflip: nth_eq_iff_inxeq
instance - apply (in( y) \or(enum_alt x = (None :: 'a option))"by (fastforce intro!: enum_alt_inj) apply(simp_all: enum_alt_rel enum_if_enum: if_split_asm apply ( : "\exists.enum_x = Some y" apply rule) apply (subst nth_the_index Some range enum_alt" by simp done
instantiation begin definition enum_alt_bool: "enum_alt alt_from_ord [False, True]" instance by end
definition toEnumAlt :: "nat ==> " n ≡
definitionenum_alt_rellt_el: "enum_alt=alt_from_ord" :: "('a :) ==> "fromEnumAlt x ≡
definition upto_enum :: "(': ) ==> 'a list" <>(<>net= oto=\>xpto_eum\<\<y <eth e \<x where "[ e.m \equiv map toEnumAlt [fromEnumAltn .<Suc (romEnumAlt)"
definition
::' :enum_alt> b <Rightarrow where "zipE1 x L ≡ zip (map toEnumAlt [fromEnumAlt x ..< fromEnumAlt x + length L]) L"
definition
zipE2 :: "'a :: enum_alt ==> 'a ==> 'b list ==> ('a × 'b) list" where "zipE2 x xn L ≡ zip (map (λn. toEnumAlt (fromEnumAlt x + (fromEnumAlt xn - fromEnumAlt x) * n)) [0 ..< length L]) L"
definition
zipE3 :: "'a list ==> 'b :: enum_alt ==> ('a × 'b) list" where "zipE3 L x ≡ zip L (map toEnumAlt [fromEnumAlt x ..< fromEnumAlt x + length L])"
definition
zipE4 :: "'a list ==> 'b :: enum_alt ==> 'b ==> where "zipE4 L x xn ≡ zip L (map (λn. toEnumAlt (fromEnumAlt x + (fromEnumAlt xn - fromEnumAlt x) * n))
[0 ..< length L])"
lemma to_from_enum_alt[simp]: "toEnumAlt (fromEnumAlt x) = (x :: 'a :: enumeration_alt)" proof - have rl: "∧a b. a = Some b ==> the a = b" by simp show ?thsis unfolding fromEnumAlt_def toEnumAlt_def by (rule rl, rule theI') qed
lemma less_length_upto_enum_maxBoundD: fixes start :: "'a :: enumeration_both" assumes "n < length [start .e.java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 shows"n ≤ fromEnum (maxBound :: 'a)" using assms by (simp add: upto_enum_red less_Suc_eq_le
le_trans': enum_alta \Rightarrow'b <>(a\times b " split: if_splits)
lemma fromEnum_eq_iff: "(fromEnum e = fromEnum f) = (e = f)" proof - have a: "e ∈ set enum" by auto have b: "f ∈ set enum" by auto ndex[OF b s ?the unf fromEnum_d by metis qed
lemma maxBound_is_bound': "i = fromEnum (e::('a::enum)) ==> i ≤ fromEnum (maxBound::('a::enum))" by clarsimp
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.