Theory Valuetypes
section‹Value types›
theory Valuetypes
imports ReadShow
begin
fun iter :: "(nat ⇒ 'b ⇒ 'b) ⇒ 'b ⇒ nat ⇒ 'b"
where
"iter f v x = (if x ≤ 0 then v
else f (x-1) (iter f v (x-1)))"
fun iter' :: "(nat ⇒ 'b ⇒ 'b option) ⇒ 'b ⇒ nat ⇒ 'b option"
where
"iter' f v x = (if x ≤ 0 then Some v
else case iter' f v (x-1) of
Some v' ⇒ f (x-1) v'
| None ⇒ None)"
type_synonym address = String.literal
type_synonym location = String.literal
type_synonym valuetype = String.literal
typedef bits = "{8::nat,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128,
136,144,152,160,168,176,184,192,200,208,216,224,232,240,248,256}"
morphisms to_nat to_bit by auto
setup_lifting type_definition_bits
lift_definition b8 :: "bits" is 8 by simp
lift_definition b16 :: "bits" is 16 by simp
lift_definition b24 :: "bits" is 24 by simp
lift_definition b32 :: "bits" is 32 by simp
lift_definition b40 :: "bits" is 40 by simp
lift_definition b48 :: "bits" is 48 by simp
lift_definition b56 :: "bits" is 56 by simp
lift_definition b64 :: "bits" is 64 by simp
lift_definition b72 :: "bits" is 72 by simp
lift_definition b80 :: "bits" is 80 by simp
lift_definition b88 :: "bits" is 88 by simp
lift_definition b96 :: "bits" is 96 by simp
lift_definition b104 :: "bits" is 104 by simp
lift_definition b112 :: "bits" is 112 by simp
lift_definition b120 :: "bits" is 120 by simp
lift_definition b128 :: "bits" is 128 by simp
lift_definition b136 :: "bits" is 136 by simp
lift_definition b144 :: "bits" is 144 by simp
lift_definition b152 :: "bits" is 152 by simp
lift_definition b160 :: "bits" is 160 by simp
lift_definition b168 :: "bits" is 168 by simp
lift_definition b176 :: "bits" is 176 by simp
lift_definition b184 :: "bits" is 184 by simp
lift_definition b192 :: "bits" is 192 by simp
lift_definition b200 :: "bits" is 200 by simp
lift_definition b208 :: "bits" is 208 by simp
lift_definition b216 :: "bits" is 216 by simp
lift_definition b224 :: "bits" is 224 by simp
lift_definition b232 :: "bits" is 232 by simp
lift_definition b240 :: "bits" is 240 by simp
lift_definition b248 :: "bits" is 248 by simp
lift_definition b256 :: "bits" is 256 by simp
declare b8.rep_eq[simp]
declare b16.rep_eq[simp]
declare b24.rep_eq[simp]
declare b32.rep_eq[simp]
declare b40.rep_eq[simp]
declare b48.rep_eq[simp]
declare b56.rep_eq[simp]
declare b64.rep_eq[simp]
declare b72.rep_eq[simp]
declare b80.rep_eq[simp]
declare b88.rep_eq[simp]
declare b96.rep_eq[simp]
declare b104.rep_eq[simp]
declare b112.rep_eq[simp]
declare b120.rep_eq[simp]
declare b128.rep_eq[simp]
declare b136.rep_eq[simp]
declare b144.rep_eq[simp]
declare b152.rep_eq[simp]
declare b160.rep_eq[simp]
declare b168.rep_eq[simp]
declare b176.rep_eq[simp]
declare b184.rep_eq[simp]
declare b192.rep_eq[simp]
declare b200.rep_eq[simp]
declare b208.rep_eq[simp]
declare b216.rep_eq[simp]
declare b224.rep_eq[simp]
declare b232.rep_eq[simp]
declare b240.rep_eq[simp]
declare b248.rep_eq[simp]
declare b256.rep_eq[simp]
instantiation bits :: linorder
begin
lift_definition less_bits :: "bits ⇒ bits ⇒ bool" is "(<)" .
lift_definition less_eq_bits :: "bits ⇒ bits ⇒ bool" is "(≤)" .
instance by (standard; transfer; linarith)
end
instantiation bits::equal
begin
lift_definition equal_bits :: "bits ⇒ bits ⇒ bool" is "(=)" .
instance by (standard; transfer; linarith)
end
declare Valuetypes.less_bits.rep_eq[simp]
declare Valuetypes.less_eq_bits.rep_eq[simp]
lemma to_nat_g_0[simp]: "to_nat b'>0" using to_nat[of b'] by auto
lemma to_nat_max_g_0[simp]: "0 < max (to_nat b1) (to_nat b2)" using to_nat_g_0[of b1] to_nat_g_0[of b2] by linarith
lemma to_nat_max[simp]: "max (to_nat b1) (to_nat b2) = to_nat (max b1 b2)" by (simp add: max_def)