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 ==> (x = y) ∨ (enum_alt x = (None :: 'a option))" begin
lemma enum_alt_inj_2: assumes"enum_alt x = (enum_alt y :: 'a option)" "enum_alt x ≠ (None :: 'a option)" shows"x = y" proof - from assms have"(x = y) ∨ (enum_alt x = (None :: 'a option))"by (fastforce intro!: enum_alt_inj) with assms show ?thesis by clarsimp qed
lemma enum_alt_surj_2: "∃x. enum_alt x = Some y" proof - have"Some y ∈ range enum_alt ∪ {None}"by (subst enum_alt_surj) simp thenhave"Some y ∈ range enum_alt"by simp thenshow ?thesis by auto qed
end
definition
alt_from_ord :: "'a list ==> nat ==> 'a option" where "alt_from_ord L ≡ λn. if (n < length L) then Some (L ! n) else None"
(*Seemingly redundant, but heavily used elsewhere*) lemma handy_if_lemma: "((if P then Some A else None) = Some B) = (P ∧ (A = B))" by simp
lemma the_index_less_length: "the_index (enum::'a::enum list) x < length (enum::'a::enum list)" by (rule the_index_bounded, simp)
lemma enum_if_enum: defines"(e::'a::enum list) ≡ enum" shows "(if x < length e then Some (e ! x) else None) = Some (e ! y) ==> y < length e ==> x = y" by (simp add: e_def split: if_split_asm flip: nth_eq_iff_index_eq [where xs=e])
definition
zipE1 :: "'a :: enum_alt ==> 'b list ==> ('a × 'b) list" 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 ==> ('a × 'b) list" 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 ?thesis unfolding fromEnumAlt_def toEnumAlt_def by (rule rl, rule theI') (metis enum_alt_inj enum_alt_surj_2 not_None_eq) qed
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 from nth_the_index[OF a] nth_the_index[OF b] show ?thesis unfolding fromEnum_def by metis qed
lemma maxBound_is_bound': "i = fromEnum (e::('a::enum)) ==> i ≤ fromEnum (maxBound::('a::enum))" by clarsimp
end
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-06-10)
¤
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.