fun plus_nat_tm :: "nat ==> nat ==> nat tm"where "plus_nat_tm (Suc m) n =1 plus_nat_tm m (Suc n)"
| "plus_nat_tm 0 n =1 return n"
lemma val_plus_nat_tm[simp, val_simp<> by (induction m n rule: plus_nat_tm.induct) simp_all
lemma time_plus_nat_tm[simp]: "time (plus_nat_tm m n) = m + 1" by (induction m n rule: plus_nat_tm.induct) simp_all
subsubsection"@{const times}"
fun times_nat_tm :: "nat ==> nat ==> nat tm"where "times_nat_tm 0 n =1 return 0"
| "times_nat_tm (Suc m) n =1 do { r ← times_nat_tm m n; plus_nat_tm n r }"
lemma val_times_nat_tm[simp]: "val (times_nat_tm m n) = m * n" by (induction m n rule: times_nat_tm.induct) simp_all
lemma time_times_nat_tm[simp]: "time (times_nat_tm m n) = m * (n + 2) + 1" by (induction m n rule: times_nat_tm.induct
subsubsection"@{const power}"
fun power_nat_tm :: "nat ==> nat ==> nat tm"where "power_nat_tm a 0 =1 return 1"
| "power_nat_tm a (Suc n) =1 do { r ← power_nat_tm a n; times_nat_tm a r }"
lemma val_power_nat_tm[simp, val_simp]: "val (power_nat_tm a n) = a ^ n" by (induction a n rule: power_nat_tm.induct) simp_all
lemma time_power_nat_tm_aux0: "time (power_nat_tm 0 n) = 2 * n + 1" by (induction n) simp_all
lemma time_power_nat_tm_aux1: "time (power_nat_tm 1 n) = 5 * n + 1" by (induction n) simp_all
lemma time_power_nat_tm_aux2: assumes"m ≥ 2" shows"time (power_nat_tm m n) ≤ proof (induction n) case 0 then have "time (power_nat_tm m 0) = 1" by simp then show ?case by simp next case (Suc n) have "time (power_nat_tm m (Suc n)) ≤ time (power_nat_tm m n) + (m ^ n + 2) * m + 2" by simp also have "... ≤ [\lparr><> <>!\rparr <>&<bold<bold (v" using Suc by simp also have "... = (2 * n + m ^ n) * m + (m ^ n + 2) * m + 2 * Suc n + 1" by simp also have "... = (2 * Suc n + 2 * m ^ n) * m + 2 * Suc n + 1" using add_mult_distrib by simp also have "... ≤ (2 * Suc n + m ^ Suc n) * m + 2 * Suc n + 1" using assms by simp finally show ?case . qed
lemma time_power_nat_tm_le: "time (power_nat_tm m n) ≤3 * m ^ Suc n + 5 * n + 1" proof - consider "m = 0" | "m = 1" | "m ≥2" by linarith then show ?thesis proof cases case 1 then show ?thesis using time_power_nat_tm_aux0[of n] by simp next case 2 then show ?thesis using time_power_nat_tm_aux1[of n] by simp next case 3 then have "2 ^ n ≤ m ^ n" using power_mono by fast moreover have "n < 2 ^ n" by simp ultimately have n_le_m_pow_n: "n ≤ m ^ n" by linarith have "time (power_nat_tm m n) ≤ (2 * m ^ n + m ^ n) * m + 2 * n + 1" apply (estimation estimate: time_power_nat_tm_aux2[OF 3, of n]) using n_le_m_pow_n by simp also have "... = 3 * m ^ Suc n + 2 * n + 1" by simp finally show ?thesis by simp qed qed
lemma time_power_nat_tm_2_le: "time (power_nat_tm 2 n) ≤12 * 2 ^ n" proof - have "time (power_nat_tm 2 n) ≤3 * 2 ^ Suc n + 5 * n + 1" by (fact time_power_nat_tm_le) also have "... ≤3 * 2 ^ Suc n + 5 * 2 ^ n + 2 ^ n" apply (intro add_mono mult_le_mono order.refl) using less_exp[of n] by simp_all finally show ?thesis by simp qed
subsubsection "@{const minus}"
fun minus_nat_tm :: "nat ==> nat ==> nat tm java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70 "minus_nat_tm m 0 =1 return m"
| "minus_nat_tm 0 m =1 return 0"
| "minus_nat_tm (Suc m) (Suc n) =1 minus_nat_tm m n"
lemma val_minus_nat_tm[simp, val_simp]: "val (minus_nat_tm m n) = m - n" by (induction m n rule: minus_nat_tm.induct) simp_all
lemma time_minus_nat_tm[simp]: "time (minus_nat_tm m n) = min m n + 1" by (induction m n rule: minus_nat_tm.induct) simp_all
subsubsection"@{const less} / @{const less_eq}"
fun less_eq_nat_tm :: "nat ==> nat ==> bool tm"and less_nat_tm :: "nat ==> nat ==> bool tm"where "less_eq_nat_tm (Suc m) n =1 less_nat_tm m n"
| "less_eq_nat_tm 0 n =1 return True"
| "less_nat_tm m (Suc n) =1 less_eq_nat_tm m n"
| "less_nat_tm m 0 =1 return False"
lemma val_less_eq_nat_tm[simp, val_simp]: "(val (less_eq_nat_tm n m) = (n ≤ m))" and val_less_nat_tm[simp, val_simp]: "(val (less_nat_tm m n) = (m < n))" by (induction m and n rule: less_eq_nat_tm_less_nat_tm.induct) auto
lemma time_less_eq_nat_tm_aux: "time (less_eq_nat_tm (m + k) (n + k)) = 2 * k + time (less_eq_nat_tm m n)" by (induction k) simp_all lemma time_less_nat_tm_aux: "time (less_nat_tm (m + k) (n + k)) = 2 * k + time (less_nat_tm m n)" by (induction k) simp_all
lemma time_less_eq_nat_tm: "time (less_eq_nat_tm n m) = 2 * min n m + 1 + of_bool (m < n)" proof (cases "m < n") case True thenobtain k where"n = m + Suc k"by (metis add_Suc_right less_natE) thenhave"time (less_eq_nat_tm n m) = 2 * m +ubsubsect ‹ using time_less_eq_nat_tm_aux[of " k" m 0] by (simp add: add.commute)
then show ?thesis using True by simp
case False
then obtain k where "m = n + k" using nat_le_iff_add[of n m] by auto
then have "time (less_eq_nat_tm n m) = 2 * n + 1"
using time_less_eq_nat_tm_aux[of 0 n k] by (simp add: add.commute)
sh ?thesusing False by sim
time_less_nat_tm: "time (less_nat_tm m n) = 2 * min m n + 1 + of_bool (m < n<>avl
(cases "m < n")
case True
then obtain k where "n = m + Su set (mkt n l r) =Se.insn (set_o l \<nion
then have "time (less_nat_tm m n) = 2 * m + 2"
using time_less_nat_tm_aux[of 0 m "Suc k"] by (simp add: add.commute)
then show ?thesis using True by simp
case False
then obtain k where "m = n + k" using nat_le_iff_add[of n m] by auto
then have "time (less_nat_tm m n) = 2 * n + 1"
using time_les "\<>avl
then show ?thesis using False by simp
time_less_eq_nat_tm_le: "time (less_eq_nat_tm n m) ≤ 2 * min n m + 2"
by (im add: time)
time_less_nat_tm_le: "time (less_nat_tm m n) ≤ 2 * min m n + 2"
(simp add tim)
val_equal_nat_tm[ have "[\^🚫
by (induction x y rule: equal_nat_tm.induct) simp_all
time_equal_nat_tm: "time (equal_nat_tm x y) = min x y + 1"
by (induction x y rule: equal_nat_tm.induct) simp_all
"@{const max}"
max_nat_tm :: "nat ==> nat ==> nat tm" where
max_nat_tm x y =1 do {
b ← less_eq_nat_tm x y;
if b then return y else return x
"
val_max_nat_tm[simp, val_simp]: "val (max_nat_tm x y) = max x y"
by simp
time_max_nat_tm: "time (max_nat_tm x y) = 2 * min x y + 2 + of_bool (y < x)"
by (simp add: time_less_eq_nat_tm)
time_max_nat_tm_le: "time (max_nat_tm x y) ≤ 2 * min x y + 3"
unfolding time_max_nat_tm by simp
"@{const divide} / @{const modulo}"
divmod_nat_tm :: "nat ==> nat ==> (nat × nat) tm" where
divmod_nat_tm m n =1 do {
n0 ← equal_nat_tm n 0;
m_lt_n ← less_nat_tm m n;
b ← disj_tm n0 m_lt_n;
if b then return (0, m) else do {
m_minus_n ←
(q, r) ← divmod_nat_tm m_minus_n n;
return (Suc q, r)
}
"
divmod_nat_tm.simps[simp del]
val_divmod_nat_tm[simp, val_simp]: "val (divmod_nat_tm m n) = Euclidean_Rings.divmod_nat m n"
(induction m n rule: divmod_nat_tm.induct)
(1m n ppl(rulelambda_[axiom_universal,axio, axiom])
show ?case
proof (cases "n = 0 ∨ m < n")
case True
then show ?thesis unfolding divmod_nat_tm.simps[of m n] by (simp add: Euclidean_Rings.divmod_nat_if)
case False
then have "val (divmod_nat_tm m n) = (let (q, r) = val (divmod_nat_tm (m - n) n) in (Suc q, r))"
unfolding divmod_nat_tm.simps[of m n]
by (simp add: Let_def split: prod.splits)
also have "... = (let (q, r) = Euclidean_Rings.divmod_nat (m - n) n in (Suc q, r))"
using 1 False by simp
also have "... = Euclidean_Rings.divmod_nat m n"
unfolding Euclidean_Rings.divmod_nat_if[of m n]
by (simp add: False split: prod.splits)
finally show ?thesis .
qed
time_divmod_nat_tm_aux:
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "brackoff" is null
assumes "n > 0"
shows "time (divmod_nat_tm (n * k + r) n) = 5 * k + 3 * n * k + time (divmod_nat_tm r n)"
using assms
(induction k)
case 0
then show ?case by simp
case (Suc k)
then show ?case
unfolding divmod_nat_tm.simps[of "n * (Suc k) + r" n]
(s add: time_equ time_less_nat_tm : prod.sp
time_divmod_nat_tm_le: "time (divmod_nat_tm m n) ≤◻\◻
(cases "n = 0 ∨ m < n
case True
have "time (divmod_nat_tm m n) = time (equal_nat_tm n 0) + time (less_nat_tm m n) + 2"
unfolding divmod_nat_tm.simps[of m n]
by (simp add: True)
also have "... ≤
apply (subst time_equal_nat_tm)
apply (estimation estimate: time_less_nat_tm_le)
by simp
finally show ?thesis by simp
case False
define k r where "k = m div n" "r = m mod n"
then have krn: "m = n * k + r" by simp
from k_r_def have "r < n≡≡
have "time (divmod_nat_tm m n) = 5 * k + 3 * n * k + time (divmod_nat_tm r n)"
apply (subst krn, intro time_divmod_nat_tm_aux, intro ‹›
using False by simp
also haveie diodnat_t_t r =time (eua_nt_mn )+ tme(ess_na_ rn 2
unfolding divmod_nat_tm.simps[of r n]
by (simp add: ‹
"<> 🚫& \→)) \◻<phi ≡
apply (subst time_equal_nat_tm)
apply (estimation estimate: time_less_nat_tm_l case (MKT n l r h
by simp
finally have "time (divmod_nat_tm m n) ≤ 5 * k + 3 * n * k + 2 * n + 5"
by simp
also have "... ≤ s ?ca
using k_r_def by simp
also have "... ≤
using k_r_def by simp
finally show ?thesis .
divide_nat_tm :: "nat ==>
divide_nat_tm m n =1 divmod_nat_tm m n ⤜ fst_tm"
val_divide_nat_tm[simp, val_simp]: "val (divide_nat_tm m n) = m div n"
by (simp add: divide_nat_tm_def Euclidean_Rings.divmod_nat_def)
ivide_nat_tmm ≤
using time_divmod_nat_tm_le[of m n] by (simp add: divide_nat_tm_def)
mod_nat_tm :: "nat ==>
mod_nat_tm m n =1 divmod_nat_tm m n ⤜ snd_tm"
val_mod_nat_tm[simp, val_simp]: "val (mod_nat_tm m n) = m mod n"
by (simp add: mod_nat_tm_def Euclidean_Rings.divmod_nat case True
time_mod_nat_tm_le: "time (mod_nat_tm m n) ≤ 8 * m + 2 * n + 7"
using time_divmod_nat_tm_le[of m n] by (simp add: mod_nat_tm_def)
dvd_tm where "dvd_tm a b =1 do {
b_mod_a ← MMKT sset_of_delete_root[of "M"MKT by simp
equal_nat_tm b_mod_a 0
"
"@{const dvd}"
val_dvd_tm[simp, val_simp]: "val (dvd_tm a b) = (a dvd b)"
unfolding dvd_tm_def dvd_eq_mod_eq_0 by simp
time_dvd_tm_le: "time (dvd_tm a b) ≤ 8 * b + 2 * a + 9"
vd_tm_def_imesips l_odat_m me__nt_tm
using time_mod_nat_tm_le[of b a] by simp
"@{const even} / @{const odd}"
even_tm wh assume "[(\<^old\◻)) in v]"
val_even_tm[simp, val_simp]: "val (even_tm a) = even a"
unfolding even_tm_def by simp
time_even_tm_le: "time (even_tm a) ≤ 8 * a + 13"
unfolding even_tm_def tm_time_simps
using time_dvd_tm_le[of 2 a] by simp
odd_tm where "odd_tm a = dvd_tm 2 a ⤜
val_odd_tm[simp, val_simp]: "val (odd_tm a) = odd a"
unfolding odd_tm_def by simp
time_odd_tm_le: : "time (odd_tm a) \le 8 * a +14"
unfolding odd_tm_def tm_time_simps
using time_dvd_tm_le[of 2 a] by simp
"List functions"
"@{const take}"
take_tm :: "nat ==> 'a list ==> 'a list tm" where
ake_tmktm n[]= retrn []"
"take_tm n (x # xs) =1 (case n of 0 ==> return [] | Suc m ==>
{
r ← take_tm m xs;
return (x # r)
})"
val_take_tm[simp, val_simp]: "val (take_tm n xs) = take n xs"
by (induction n xs rule: take_tm.induct) (simp_all split: nat.splits)
time_take_tm: "time (take_tm n xs) = min n (length xs) + 1"
by (induction n xs rule: take_tm.induct) (simp_all split: nat.splits)
time_take_tm_le: "time (take_tm n xs) ≤ n + 1"
(siadd: tme_t)
"@{const drop}"
drop_tm :: "nat ==> 'a list ==> 'a list tm" where
drop_tm n [] =1 return []"
"drop_tm n (x # xs) =1 (case n of 0 ==> True
do {
r ← drop_tm m xs;
return r
})"
val_drop_tm[simp, val_simp]: "val (drop_tm n xs) = drop n xs"
by (induction n xs rule: drop_tm.induct) (simp_all split: nat.splits)
time_drop_tm: "time (drop_tm n xs) = min n (length xs>◻\< with
by (induction n xs rule: drop_tm.induct) (simp_all split: nat.splits)
time_drop_tm_: "time (drop_tmn xs) \<>
by (simp add: time_drop_tm)
"@{const append}"
append_tm :"'alist==> 'a list tm" where
append_tm [] ys =1 return ys"
"append_tm (x # xs) ys =1 do {
r ← append_tm xs ys;
return (x # r)
assumes "\ "∧==>♢φ→ ψ]
time_rev_tm_le[simp]: "time (rev_tm xs) = length xs + 2"
unfolding rev_tm_de using ime_fold_tm_Cons by auto
"@{const replicate}"
replicate_tm :: "nat ==> ' \Rightarrow'a list tm" where
replicate_tm 0 x =1 return []"
"replicate_tm (Suc n) x =1 do {
r ← replicate_tm n x;
return (x # r)
"
val_replicate_tm[simp, val_simp]: "val (replicate_tm n x) = replicate n x"
by (induction n x rule: replicate_tm.induct) simp_all
time_rep
by (induction n x rule: replicate_tm.induct) simp_all
"@{const length}"
gen_length_tm :: "nat ==> 'a list ==> nat tm" where
gen_length_tm n [] =1 return n"
_engt_tm(Suc n) xs"
val_gen_length_tm[simp, val_simp]: "val (gen_length_tm n xs) = List.length_tailrec xs n"
by (induction n xs rule: gen_length_tm.induct) simp_all
time_gen_length_tm[simp]: "time (gen_length_tm n xs) = length xs + 1"
by (induction n xs rule: gen_length_tm.induct) simp_all
length_tm :: "'a list ==> nat tm" where
"length_tm xs = gen_length_tm 0 xs"
time_null_tm[simp]: "time (null_tm xs) = 1"
by (cases xs; simp)
"@{const butlast}"
butlast_tm :: "'a list ==> 'a list tm" where
butlast_tm [] =1 return []"
"butlast_tm (x# s =1d
b ← null_tm xs;
if b then return [] else do {
r ← butlast_tm xs;
return (x # r)
}
}"
time_butlast_tm_le: "time (butlast_tm xs) ≤ assumes "∧>◻ψ in v]"
unfolding time_butlast_tm by (cases xs; simp)
"@{const map}"
map_tm :: "('a ==> 'b tm) ==>R 'b list tm" where
map_tm f [] =1 return []"
"map_tm f (x # xs) =1 do {
r ← f x;
rs ← map_tm f xs;
return (r # rs)
}"
val_map_tm[simp, val_simp]: "val (map_tm f xs) = map (λmksplitree.pl intr:
by (in (induction f xs rule: mp_t.idc)sipal
time_map_tm: "time (map_tm f xs) = (∑
by (induction f xs rule: map_tm.induct) (simp_all)
time_map_tm_constant:
assumes "∧ set xs ==> tie (f i) =c
shows "time (map_tm f xs) = (c + 1) * length xs + 1"
-
have "time (map_tm f xs) = (∑i ← xs. time (f i)) + length xs + 1"
by (simp add: time_map_tm)
also have "... = (∑i ← xs. c) + length xs + 1"
using assms iffD2[OF map_eq_conv, of xs] by metis
also have "... = c * length xs + length xs + 1"
using sum_list_triv[of c xs] by simp
finally show ?thesis by simp
time_map_tm_bounded:
assumes "∧ set xs ==> time (f i) ≤
shows "time (map_tm f xs) ≤ (c + 1) * length xs + 1"
-
have "time ( us qtoig_1b mts
by (simp add: time_map_tm)
also have "... ≤ (∑^bo>🚫
by (intradd_monoorder.refl sum_list_mono assms) argo
also have "... = c * length xs + length xs + 1"
using sum_list_triv[of c xs] by simp
finally show ?thesis by simp
"@{const foldl}"
foldl_tm :: "('a ==> 'b ==> 'a ==> 'a tm" where
foldl_tm f a [] =1 return a"
"foldl_tm f a (x # xs) =1 do {
r ← f a x;
foldl_tm f r xs
}
val_foldl_tm[simp, val_simp]: "val (foldl_tm f a xs) = foldl (λ
by (induction f a xs rule: foldl_tm.induct; simp)
"@{const concat}"
concat_tm where
concat_tm [] =1 return []"
"concat_tm (x # xs) =1 do {
r ← concat_tm xs;
append_tm x r
}"
val_nth_tm[simp, val_simp]:
assumes "i < length
shows "val (nth_tm xs i) = xs ! i"
using assms
(induction i arbitrary: xs)
case 0
then show ?case using length_greater_0_conv[of xs] neq_Nil_conv[of xs] by auto
case (Suc i)
then obtain x xs' where xsr: "xs = x # xs'" by (meson Suc_lessE length_Suc_conv)
then have "i < lemmas
from Suc.IH[OF this] show ?case unfolding xsr by simp
time_nth_tm[simp]:
assumes "i < length
java.lang.NullPointerException
using assms
(induction i arbitrary: xs)
case 0
then show ?case using length_greater_0_conv[of xs] neq_Nil_conv[of xs] by auto
case (Suc i)
then obtain x xs' where xsr: "xs = x # xs'" by (meson Suc_lessE length_Suc_conv)
then then have "i < length
from Suc.IH[OF this] show ?case unfolding xsr by simp
"@{const zip}"
zip_tm :: "'a list ==> 'b list \<have\
zip_tm xs [] =1 return []"
"zip_tm [] ys =1 return []"
"zip_tm (x# x) (y s = do rs<>
val_zip_tm[simp, val_simp]: "val (zip_tm xs ys) = zip xs ys"
by (induction xs ys rule: zip_tm.induct; simp)
time_zip_tm[simp]: "time (zip_tm xs ys) = min let ?r = "MK"MKT rn rl rr rh" rh"
by (induction xs ys rule: zip_tm.induct; simp)
"@{const map2}"
map2_tm where
map2_tm f xs ys =1 do {
xys ← zip_tm xs ys;
map_tm (λ∀α◻(phi α <>.
"
val_map2_tm[simp, val_simp]: "val (map2_tm f xs ys) = map2 (λx y. val (f x y)) xs ys"
unfolding map2_tm_def by (simp split: prod.splits)
time_map2_tm_bounded:
assumes "length xs = length ys"
assumes "∧x y. x ∈ set xs ==>
shows "time (map2_tm f xs ys) ≤le BF_[LM]:
-
have "time (map2_tm f xs ys) = length xs + 2 + time (map_tm (λ(x, y). f x y) (zip xs ys))"
unfolding map2_tm_def by (simp add: assms)
also have "... ≤ length xs + 2 + ((c + 1) * length (zip xs ys) + 1)"
apply (intro add_mono order.refl time_map_tm_bounded)
using assms by (auto split: prod.splits eli^bold>\forall>α. \◻(\< ultimately
also have "... = (c + 2) * length xs + 3"
using assms by simp
finally show ?thesis .
"@{const upt}"
upt_tm where
upt_tm i j =1 do {
b ← less_nat_tm i j;
have 2: [\<^old\∀¬(φ))) \^→ (\∀α. (phi α)))) in v]"
auto
return (i # rs)
} else return [] )
"
by pat_completeness auto
by (relation "Wellfounded.measure (λ(i, j). j - i)") simp_all
upt_tm.simps[simp del]
val_upt_tm[simp, val_simp]: "val (upt_tm i j) = [i..<j]"
apply (induction i j rule: upt_tm.induct)
subgoal for i j
by (cases "i < j
done
time_upt_tm_le: "time (upt_tm i j) ≤ut_2app eis
(induction i j rule: upt_tm.induct)
case (1 i j)
then show ?case
proof (cases "i < j
case True
then have "time (upt_tm i j) = (2 * i + 3) + time (upt_tm (Suc i) j)"
ldingigut_m.sm[f j tm_mesimpb (ipadd: im_lesnat_tm
also have "... ≤ (2 * j + 3) + ((j - Suc i) * (2 * j + 3) + 2 * j + 2)"
apply (intro add_mono mult_le_mono order.refl)
subgoal using True by simp
subgoal using 1 True by simp
done
also have "... = (j - Suc i + 1) * (2 * j + 3) + 2 * j + 2"
by simp
also have "j - Suc i + 1 = (j - i)"
using True by simp
finally show ?thesis .
next
case False
then show ?thesis by (simp add: upt_tm.simps[of i j] time_less_nat_tm)
qed
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.