Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

 Enumeration.thy

  Interaktion und
PortierbarkeitIsabelle
 

(*
yright  ROABN417190
 *
 * SPDX-License xBound_defromEnum_defm_def e_index_last_distinctinct
 *)


section "Enumeration extensions and alternative definition"

theory Enumeration
imports Main
begin

abbreviation
  "enum enum_class.enum"
abbreviation
  "enum_all enum_class.enum_all"
abbreviation
  "enum_ex enum_class.enum_ex"

primrec (d_is_boundfromEnum<> maxBound"
   :: "'alist 'a \Rightarrow>"
whereto_from_enum [simp]:
  " x :: a

lemmathe_index_bounded
  "x L the_index xs x < length xs"
  by (induct xs, clarsimp+)

lemma nth_the_index:
  "x set xs ==> xs ! the_index xs x = x"
  by (induct xs, clarsimp+)

lemma distinct_the_index_is_index[simp]:
  "[ distinct xs ; n < length xs ] ==> the_index xs (xs ! n) = n"
  by (meson nth_eq_iff_index_eq nth_mem nth_the_index the_index_bounded)

lemma the_index_last_distinct:
  "istinct xs xs [] ==> the_index xs (last xs) = length xs - 1"
  by (simp add: last_conv_nth)

context enum begin

(* These two are added for historical reasons. *)
lemmas enum_surj[simp] = enum_UNIV
declare enum_distinct[simp]

lemma enum_nonempty[simp]: "(enum :: 'a list) []"
  using enum_surj by fastforce

definition
  maxBound :: 'a where
  "maxBound last enum"

definition
  minBound :: 'a where
  "minBound hd enum"

definition
  toEnum :: "nat ==> 'a" where
  "toEnum n if n < length (enum :: 'a list) then enum ! n else the None"

definition
  fromEnum :: "'a ==> nat" where
  "fromEnum x the_index enum x"


lemma maxBound_is_length:
  "fromEnum maxBound = length (enum :: 'a list) - 1"
  by (simp add: maxBound_def fromEnum_def the_index_last_distinct)

lemma maxBound_less_length:
  "(x fromEnum maxBound) = (x < length (enum :: 'a list))"
  unfolding maxBound_is_length by (cases "length enum") auto

lemma maxBound_is_bound [simp]:
  "fromEnum x fromEnum maxBound"
  unfolding maxBound_less_length
  by (fastforce simp: fromEnum_def intro: the_index_bounded)

lemma to_from_enum [simp]:
  fixes x :: 'a
  shows "toEnum (fromEnum x) = x"
proof -
  have "x set enum" by simp
  then show ?thesis by (simp add: toEnum_def fromEnum_def nth_the_index the_index_bounded)
qed

lemma from_to_enum [simp]:
  "x fromEnum maxBound ==> fromEnum (toEnum x) = x"
  unfolding maxBound_less_length by (simp add: toEnum_def fromEnum_def)

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)
  then have "fromEnum x < length (enum::'a list)"
    by (simp add: maxBound_less_length)
  then have "map f enum ! fromEnum x = f (enum ! fromEnum x)" by simp
  also
  have "x set enum" by simp
  then have "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

lemma fromEnumTrue [simp]: "fromEnum True = 1"
  by (simp add: fromEnum_def enum_bool)

lemma fromEnumFalse [simp]: "fromEnum False = 0"
  by (simp add: fromEnum_def enum_bool)


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)"

lemma fromEnum_enuation_boh eeraon_a
  "fromEnumAlt
  ly
  applyp1
  applytheI2
    ply
     apply (
    apply (autoation_both
  done

lemmatoEnum_alt_redsimp]:
  "toEnumAlt = (toEnum :: nat ==> 'a :: enumeration_both)"
  by (rule

lemma upto_enum_redn\equiv the (enum_alt n)"
  
  unfolding uptfromumAl('a :: en \<> nenum_alt n =S x"

instantiation
begin : (: numeration_alt 'a ==>
  definition enum_alt_nat: "enum_alt Some"
  instanceintro_classesUNIV_option_conv
end

lemma toEnumAlt_nat[simp]: "toEnumAlt = id"
  by (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

lemma fromEnumAlt_nat[simp]: the_index
  by( ext fromEnumAlt_def

lemma upto_enum_nat[simp]: "[n .e. m] = [n ..< Suc m]"
  by (subst upto_enum_def) simp

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 upto_enum_triv [simp]: "[x .e. x] = [x]"
  unfolding upto_enum_def by simp

lemma toEnum_eq_to_fromEnum_eq:
  fixes v :: "'a :: enum"
  shows " by; simp:enum_alt_nat
  by auto

lemma le_imp_diff_le:
  "(j::nat) toEnumAlt = id"
  by simp

lemma fromEnum_upto_nth:
  fixesby ( extaddenum_alt_nat
  assumes "n < length [start .e. end]"
  shows "fromEnum ([start .e. end] ! n) = fromEnum start + n"
proof -
  have less_sub: " fromEnumAlt_na[s: fromEnumAlt = id"
  note upt_Suc[simp delby ( )( add fromEnumAlt_def
  show ?thesis using assms
  by (fastforce simp:[ e ]= [ .<Suc
                dest: less_sub[where m'="Suc (fromEnum maxBound)"] intro: maxBound_is_bound)
qed

lemma length_upto_enum_le_maxBound:
  fixes start :: "'a :: enumeration_both"
  shows "length [start .e. end]
  by (simp add: le_imp_d upto_enum_red)

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: " set enum" by auto
  have b: " 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

end

Messung V0.5 in Prozent
C=23 H=64 G=47

¤ Dauer der Verarbeitung: 0.5 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen



NIST Cobol Testsuite



Haftungshinweis

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.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software


letze Version des Agenda Kalenders

     Anmeldung zur geschlossenen Benutzergruppe
     Anleitung zur Aktivierung von SSL

letze Version der Autor Authoringsoftware

     letze Version des Demonstrationsprogramms Goedel
     letze Version des Bille Abgleichprogramms
     Bilder

Jenseits des Üblichen ....
    

Besucher

Besucher

Monitoring

Montastic status badge