text‹This file contains various definitions and lemmata not closely related to finite state
machines or testing.›
theory Util imports Main "HOL-Library.FSet""HOL-Library.Sublist""HOL-Library.Mapping" begin
subsection‹Converting Sets to Maps›
text‹This subsection introduces a function @{text "set_as_map"} that transforms a set of
@{text "('a × 'b)"} tuples to a map mapping each first value @{text "x"} of the contained tuples
to all second values @{text "y"} such that @{text "(x,y)"} is contained in the set.›
definition set_as_map :: "('a × 'c) set ==> ('a ==> 'c set option)"where "set_as_map s = (λ x . if (∃ z . (x,z) ∈ s) then Some {z . (x,z) ∈ s} else None)"
lemma set_as_map_code[code] : "set_as_map (set xs) = (foldl (λ m (x,z) . case m x of None ==> m (x ↦ {z}) | Some zs ==> m (x ↦ (insert z zs))) Map.empty xs)" proof - let ?f = "λ xs . (foldl (λ m (x,z) . case m x of None ==> m (x ↦ {z}) | Some zs ==> m (x ↦ (insert z zs))) Map.empty xs)" have"(?f xs) = (λ x . if (∃ z . (x,z) ∈ set xs) then Some {z . (x,z) ∈ set xs} else None)" proof (induction xs rule: rev_induct) case Nil thenshow ?caseby auto next case (snoc xz xs) thenobtain x z where"xz = (x,z)" by force
have *: "(?f (xs@[(x,z)])) = (case (?f xs) x of None ==> (?f xs) (x ↦ {z}) | Some zs ==> (?f xs) (x ↦ (insert z zs)))" by auto
thenshow ?caseproof (cases "(?f xs) x") case None thenhave **: "(?f (xs@[(x,z)])) = (?f xs) (x ↦ {z})"using * by auto
have scheme: "∧ m k v . (m(k ↦ v)) = (λk' . if k' = k then Some v else m k')" by auto
have m1: "(?f (xs@[(x,z)])) = (λ x' . if x' = x then Some {z} else (?f xs) x')" unfolding ** unfolding scheme by force
have"(λ x . if (∃ z . (x,z) ∈ set xs) then Some {z . (x,z) ∈ set xs} else None) x = None" using None snoc by auto thenhave"¬(∃ z . (x,z) ∈ set xs)" by (metis (mono_tags, lifting) option.distinct(1)) thenhave"(∃ z . (x,z) ∈ set (xs@[(x,z)]))"and"{z' . (x,z') ∈ set (xs@[(x,z)])} = {z}" by auto thenhave m2: "(λ x' . if (∃ z' . (x',z') ∈ set (xs@[(x,z)])) then Some {z' . (x',z') ∈ set (xs@[(x,z)])} else None) = (λ x' . if x' = x then Some {z} else (λ x . if (∃ z . (x,z) ∈ set xs) then Some {z . (x,z) ∈ set xs} else None) x')" by force
show ?thesis using m1 m2 snoc using‹xz = (x, z)›by presburger next case (Some zs) thenhave **: "(?f (xs@[(x,z)])) = (?f xs) (x ↦ (insert z zs))"using * by auto have scheme: "∧ m k v . (m(k ↦ v)) = (λk' . if k' = k then Some v else m k')" by auto
have m1: "(?f (xs@[(x,z)])) = (λ x' . if x' = x then Some (insert z zs) else (?f xs) x')" unfolding ** unfolding scheme by force
have"(λ x . if (∃ z . (x,z) ∈ set xs) then Some {z . (x,z) ∈ set xs} else None) x = Some zs" using Some snoc by auto thenhave"(∃ z . (x,z) ∈ set xs)" unfolding case_prod_conv using option.distinct(2) by metis thenhave"(∃ z . (x,z) ∈ set (xs@[(x,z)]))"by simp
have"{z' . (x,z') ∈ set (xs@[(x,z)])} = insert z zs" proof - have"Some {z . (x,z) ∈ set xs} = Some zs" using‹(λ x . if (∃ z . (x,z) ∈ set xs) then Some {z . (x,z) ∈ set xs} else None) x
= Some zs› unfolding case_prod_conv using option.distinct(2) by metis thenhave"{z . (x,z) ∈ set xs} = zs"by auto thenshow ?thesis by auto qed
have"∧ a . (λ x' . if (∃ z' . (x',z') ∈ set (xs@[(x,z)])) then Some {z' . (x',z') ∈ set (xs@[(x,z)])} else None) a = (λ x' . if x' = x then Some (insert z zs) else (λ x . if (∃ z . (x,z) ∈ set xs) then Some {z . (x,z) ∈ set xs} else None) x') a" proof - fix a show"(λ x' . if (∃ z' . (x',z') ∈ set (xs@[(x,z)])) then Some {z' . (x',z') ∈ set (xs@[(x,z)])} else None) a = (λ x' . if x' = x then Some (insert z zs) else (λ x . if (∃ z . (x,z) ∈ set xs) then Some {z . (x,z) ∈ set xs} else None) x') a" using‹{z' . (x,z') ∈ set (xs@[(x,z)])} = insert z zs›‹(∃ z . (x,z) ∈ set (xs@[(x,z)]))› by (cases "a = x"; auto) qed
thenhave m2: "(λ x' . if (∃ z' . (x',z') ∈ set (xs@[(x,z)])) then Some {z' . (x',z') ∈ set (xs@[(x,z)])} else None) = (λ x' . if x' = x then Some (insert z zs) else (λ x . if (∃ z . (x,z) ∈ set xs) then Some {z . (x,z) ∈ set xs} else None) x')" by auto
show ?thesis using m1 m2 snoc using‹xz = (x, z)›by presburger qed qed
thenshow ?thesis unfolding set_as_map_def by simp qed
abbreviation"member_option x ms ≡ (case ms of None ==> False | Some xs ==> x ∈ xs)" notation member_option (‹(_∈o_)› [1000] 1000)
abbreviation(input) "lookup_with_default f d ≡ (λ x . case f x of None ==> d | Some xs ==> xs)" abbreviation(input) "m2f f ≡ lookup_with_default f {}"
abbreviation(input) "lookup_with_default_by f g d ≡ (λ x . case f x of None ==> g d | Some xs ==> g xs)" abbreviation(input) "m2f_by g f ≡ lookup_with_default_by f g {}"
lemma m2f_by_from_m2f : "(m2f_by g f xs) = g (m2f f xs)" by (simp add: option.case_eq_if)
lemma set_as_map_containment : assumes"(x,y) ∈ zs" shows"y ∈ (m2f (set_as_map zs)) x" using assms unfolding set_as_map_def by auto
lemma set_as_map_elem : assumes"y ∈ m2f (set_as_map xs) x" shows"(x,y) ∈ xs" using assms unfolding set_as_map_def proof - assume a1: "y ∈ (case if ∃z. (x, z) ∈ xs then Some {z. (x, z) ∈ xs} else None of None ==> {} | Some xs ==> xs)" thenhave"∃a. (x, a) ∈ xs" using all_not_in_conv by fastforce thenshow ?thesis using a1 by simp qed
subsection‹Utility Lemmata for existing functions on lists›
subsubsection‹Utility Lemmata for @{text "find"}›
lemma find_result_props : assumes"find P xs = Some x" shows"x ∈ set xs"and"P x" proof - show"x ∈ set xs"using assms by (metis find_Some_iff nth_mem) show"P x"using assms by (metis find_Some_iff) qed
lemma find_set : assumes"find P xs = Some x" shows"x ∈ set xs" using assms proof(induction xs) case Nil thenshow ?caseby auto next case (Cons a xs) thenshow ?case by (metis find.simps(2) list.set_intros(1) list.set_intros(2) option.inject) qed
lemma find_condition : assumes"find P xs = Some x" shows"P x" using assms proof(induction xs) case Nil thenshow ?caseby auto next case (Cons a xs) thenshow ?case by (metis find.simps(2) option.inject) qed
lemma find_from : assumes"∃ x ∈ set xs . P x" shows"find P xs ≠ None" by (metis assms find_None_iff)
lemma find_sort_containment : assumes"find P (sort xs) = Some x" shows"x ∈ set xs" using assms find_set by force
lemma find_sort_index : assumes"find P xs = Some x" shows"∃ i < length xs . xs ! i = x ∧ (∀ j < i . ¬ P (xs ! j))" using assms proof (induction xs arbitrary: x) case Nil thenshow ?caseby auto next case (Cons a xs) show ?caseproof (cases "P a") case True thenshow ?thesis using Cons.prems unfolding find.simps by auto next case False thenhave"find P (a#xs) = find P xs" unfolding find.simps by auto thenhave"find P xs = Some x" using Cons.prems by auto thenshow ?thesis using Cons.IH False by (metis Cons.prems find_Some_iff) qed qed
lemma find_sort_least : assumes"find P (sort xs) = Some x" shows"∀ x' ∈ set xs . x ≤ x' ∨¬ P x'" and"x = (LEAST x' ∈ set xs . P x')" proof - obtain i where"i < length (sort xs)" and"(sort xs) ! i = x" and"(∀ j < i . ¬ P ((sort xs) ! j))" using find_sort_index[OF assms] by blast
have"∧ j . j > i ==> j < length xs ==> (sort xs) ! i ≤ (sort xs) ! j" by (simp add: sorted_nth_mono) thenhave"∧ j . j < length xs ==> (sort xs) ! i ≤ (sort xs) ! j ∨¬ P ((sort xs) ! j)" using‹(∀ j < i . ¬ P ((sort xs) ! j))› by (metis not_less_iff_gr_or_eq order_refl) thenshow"∀ x' ∈ set xs . x ≤ x' ∨¬ P x'" by (metis ‹sort xs ! i = x› in_set_conv_nth length_sort set_sort) thenshow"x = (LEAST x' ∈ set xs . P x')" using find_set[OF assms] find_condition[OF assms] by (metis (mono_tags, lifting) Least_equality set_sort) qed
subsubsection‹Utility Lemmata for @{text "filter"}›
lemma filter_take_length : "length (filter P (take i xs)) ≤ length (filter P xs)" by (metis append_take_drop_id filter_append le0 le_add_same_cancel1 length_append)
lemma filter_double : assumes"x ∈ set (filter P1 xs)" and"P2 x" shows"x ∈ set (filter P2 (filter P1 xs))" using assms by simp
lemma filter_list_set : assumes"x ∈ set xs" and"P x" shows"x ∈ set (filter P xs)" by (simp add: assms(1) assms(2))
lemma filter_list_set_not_contained : assumes"x ∈ set xs" and"¬ P x" shows"x ∉ set (filter P xs)" by (simp add: assms(1) assms(2))
lemma filter_map_elem : "t ∈ set (map g (filter f xs)) ==>∃ x ∈ set xs . f x ∧ t = g x" by auto
subsubsection‹Utility Lemmata for @{text "concat"}›
lemma concat_map_elem : assumes"y ∈ set (concat (map f xs))" obtains x where"x ∈ set xs" and"y ∈ set (f x)" using assms proof (induction xs) case Nil thenshow ?caseby auto next case (Cons a xs) thenshow ?case proof (cases "y ∈ set (f a)") case True thenshow ?thesis using Cons.prems(1) by auto next case False thenhave"y ∈ set (concat (map f xs))" using Cons by auto have"∃ x . x ∈ set xs ∧ y ∈ set (f x)" proof (rule ccontr) assume"¬(∃x. x ∈ set xs ∧ y ∈ set (f x))" thenhave"¬(y ∈ set (concat (map f xs)))" by auto thenshow False using‹y ∈ set (concat (map f xs))›by auto qed thenshow ?thesis using Cons.prems(1) by auto qed qed
lemma set_concat_map_sublist : assumes"x ∈ set (concat (map f xs))" and"set xs ⊆ set xs'" shows"x ∈ set (concat (map f xs'))" using assms by (induction xs) (auto)
lemma set_concat_map_elem : assumes"x ∈ set (concat (map f xs))" shows"∃ x' ∈ set xs . x ∈ set (f x')" using assms by auto
lemma concat_replicate_length : "length (concat (replicate n xs)) = n * (length xs)" by (induction n; simp)
subsection‹Enumerating Lists›
fun lists_of_length :: "'a list ==> nat ==> 'a list list"where "lists_of_length T 0 = [[]]" | "lists_of_length T (Suc n) = concat (map (λ xs . map (λ x . x#xs) T ) (lists_of_length T n))"
lemma lists_of_length_containment : assumes"set xs ⊆ set T" and"length xs = n" shows"xs ∈ set (lists_of_length T n)" using assms proof (induction xs arbitrary: n) case Nil thenshow ?caseby auto next case (Cons a xs) thenobtain k where"n = Suc k" by auto thenhave"xs ∈ set (lists_of_length T k)" using Cons by auto moreoverhave"a ∈ set T" using Cons by auto ultimatelyshow ?case using‹n = Suc k›by auto qed
lemma lists_of_length_length : assumes"xs ∈ set (lists_of_length T n)" shows"length xs = n" proof - have"∀ xs ∈ set (lists_of_length T n) . length xs = n" by (induction n; simp) thenshow ?thesis using assms by blast qed
lemma lists_of_length_elems : assumes"xs ∈ set (lists_of_length T n)" shows"set xs ⊆ set T" proof - have"∀ xs ∈ set (lists_of_length T n) . set xs ⊆ set T" by (induction n; simp) thenshow ?thesis using assms by blast qed
lemma lists_of_length_list_set : "set (lists_of_length xs k) = {xs' . length xs' = k ∧ set xs' ⊆ set xs}" using lists_of_length_containment[of _ xs k]
lists_of_length_length[of _ xs k]
lists_of_length_elems[of _ xs k] by blast
subsubsection‹Enumerating List Subsets›
fun generate_selector_lists :: "nat ==> bool list list"where "generate_selector_lists k = lists_of_length [False,True] k"
lemma generate_selector_lists_set : "set (generate_selector_lists k) = {(bs :: bool list) . length bs = k}" using lists_of_length_list_set by auto
lemma selector_list_index_set: assumes"length ms = length bs" shows"set (map fst (filter snd (zip ms bs))) = { ms ! i | i . i < length bs ∧ bs ! i}" using assms proof (induction bs arbitrary: ms rule: rev_induct) case Nil thenshow ?caseby auto next case (snoc b bs) let ?ms = "butlast ms" let ?m = "last ms"
have"length ?ms = length bs"using snoc.prems by auto
have"{ms ! i |i. i < length (bs @ [b]) ∧ (bs @ [b]) ! i} = {ms ! i |i. i ≤ (length bs) ∧ (bs @ [b]) ! i}" by auto moreoverhave"{ms ! i |i. i ≤ (length bs) ∧ (bs @ [b]) ! i} = {ms ! i |i. i < length bs ∧ (bs @ [b]) ! i} ∪ {ms ! i |i. i = length bs ∧ (bs @ [b]) ! i}" by fastforce moreoverhave"{ms ! i |i. i < length bs ∧ (bs @ [b]) ! i} = {?ms ! i |i. i < length bs ∧ bs ! i}" using‹length ?ms = length bs›by (metis butlast_snoc nth_butlast) ultimatelyhave **: "{ms ! i |i. i < length (bs @ [b]) ∧ (bs @ [b]) ! i} = {?ms ! i |i. i < length bs ∧ bs ! i} ∪ {ms ! i |i. i = length bs ∧ (bs @ [b]) ! i}" by simp
have"set (map fst (filter snd (zip [?m] [b]))) = {ms ! i |i. i = length bs ∧ (bs @ [b]) ! i}" proof (cases b) case True thenhave"set (map fst (filter snd (zip [?m] [b]))) = {?m}"by fastforce moreoverhave"{ms ! i |i. i = length bs ∧ (bs @ [b]) ! i} = {?m}" proof - have"(bs @ [b]) ! length bs" by (simp add: True) moreoverhave"ms ! length bs = ?m" by (metis last_conv_nth length_0_conv length_butlast snoc.prems snoc_eq_iff_butlast) ultimatelyshow ?thesis by fastforce qed ultimatelyshow ?thesis by auto next case False thenshow ?thesis by auto qed
thenhave"set (map fst (filter snd (zip (butlast ms) bs))) ∪ set (map fst (filter snd (zip [?m] [b]))) = {butlast ms ! i |i. i < length bs ∧ bs ! i} ∪ {ms ! i |i. i = length bs ∧ (bs @ [b]) ! i}" using snoc.IH[OF ‹length ?ms = length bs›] by blast
thenshow ?caseusing * ** by simp qed
lemma selector_list_ex : assumes"set xs ⊆ set ms" shows"∃ bs . length bs = length ms ∧ set xs = set (map fst (filter snd (zip ms bs)))" using assms proof (induction xs rule: rev_induct) case Nil let ?bs = "replicate (length ms) False" have"set [] = set (map fst (filter snd (zip ms ?bs)))" by (metis filter_False in_set_zip length_replicate list.simps(8) nth_replicate) moreoverhave"length ?bs = length ms"by auto ultimatelyshow ?caseby blast next case (snoc a xs) thenhave"set xs ⊆ set ms"and"a ∈ set ms"by auto thenobtain bs where"length bs = length ms"and"set xs = set (map fst (filter snd (zip ms bs)))" using snoc.IH by auto
from‹a ∈ set ms›obtain i where"i < length ms"and"ms ! i = a" by (meson in_set_conv_nth)
let ?bs = "list_update bs i True" have"length ms = length ?bs"using‹length bs = length ms›by auto have"length ?bs = length bs"by auto
have"set (map fst (filter snd (zip ms ?bs))) = {ms ! i |i. i < length ?bs ∧ ?bs ! i}" using selector_list_index_set[OF ‹length ms = length ?bs›] by assumption
have"(hd cs) ∈ set ((fst xys, None) # (map (λ y . (fst xys, Some y)) (snd xys)))" using‹fst (hd cs) = fst xys› ‹(snd (hd cs) = None ∨ (snd (hd cs) ≠ None ∧ the (snd (hd cs)) ∈ set (snd xys)))› by (metis (no_types, lifting) image_eqI list.set_intros(1) list.set_intros(2)
option.collapse prod.collapse set_map)
show"cs ∈ set (generate_choices ((xys#(a#xyss))))" using generate_choices.simps(2)[of xys "a#xyss"]
concat_map_hd_tl_elem[OF ‹(hd cs) ∈ set ((fst xys, None) # (map (λ y . (fst xys, Some y)) (snd xys)))› ‹(tl cs ∈ set (generate_choices (a#xyss)))› ‹length cs > 0›] by auto qed
moreoverhave"cs ∈ set (generate_choices (xys#a#xyss)) ==> length cs = length (xys#a#xyss) ∧ fst (hd cs) = fst xys ∧ ((snd (hd cs) = None ∨ (snd (hd cs) ≠ None ∧ the (snd (hd cs)) ∈ set (snd xys)))) ∧ (tl cs ∈ set (generate_choices (a#xyss)))" proof - assume"cs ∈ set (generate_choices (xys#a#xyss))" thenhave p3: "tl cs ∈ set (generate_choices (a#xyss))" using generate_choices.simps(2)[of xys "a#xyss"] by fastforce thenhave"length (tl cs) = length (a # xyss)"using Cons.IH[of "tl cs""a"] by simp thenhave p1: "length cs = length (xys#a#xyss)"by auto
have p2 : "fst (hd cs) = fst xys ∧ ((snd (hd cs) = None ∨ (snd (hd cs) ≠ None ∧ the (snd (hd cs)) ∈ set (snd xys))))" using‹cs ∈ set (generate_choices (xys#a#xyss))› generate_choices.simps(2)[of xys "a#xyss"] by fastforce
show ?thesis using p1 p2 p3 by simp qed
ultimatelyshow ?caseby blast qed
lemma list_append_idx_prop : "(∀ i . (i < length xs ⟶ P (xs ! i))) = (∀ j . ((j < length (ys@xs) ∧ j ≥ length ys) ⟶ P ((ys@xs) ! j)))" proof - have"∧ j . ∀i<length xs. P (xs ! i) ==> j < length (ys @ xs) ==> length ys ≤ j ⟶ P ((ys @ xs) ! j)" by (simp add: nth_append) moreoverhave"∧ i . (∀ j . ((j < length (ys@xs) ∧ j ≥ length ys) ⟶ P ((ys@xs) ! j))) ==> i < length xs ==> P (xs ! i)" proof - fix i assume"(∀ j . ((j < length (ys@xs) ∧ j ≥ length ys) ⟶ P ((ys@xs) ! j)))" and"i < length xs" thenhave"P ((ys@xs) ! (length ys + i))" by (metis add_strict_left_mono le_add1 length_append) moreoverhave"P (xs ! i) = P ((ys@xs) ! (length ys + i))" by simp ultimatelyshow"P (xs ! i)"by blast qed ultimatelyshow ?thesis by blast qed
lemma list_append_idx_prop2 : assumes"length xs' = length xs" and"length ys' = length ys" shows"(∀ i . (i < length xs ⟶ P (xs ! i) (xs' ! i))) = (∀ j . ((j < length (ys@xs) ∧ j ≥ length ys) ⟶ P ((ys@xs) ! j) ((ys'@xs') ! j)))" proof - have"∀i<length xs. P (xs ! i) (xs' ! i) ==> ∀j. j < length (ys @ xs) ∧ length ys ≤ j ⟶ P ((ys @ xs) ! j) ((ys' @ xs') ! j)" using assms proof - assume a1: "∀i<length xs. P (xs ! i) (xs' ! i)"
{ fix nn :: nat have ff1: "∀n na. (na::nat) + n - n = na" by simp have ff2: "∀n na. (na::nat) ≤ n + na" by auto thenhave ff3: "∀as n. (ys' @ as) ! n = as ! (n - length ys) ∨¬ length ys ≤ n" using ff1 by (metis (no_types) add.commute assms(2) eq_diff_iff nth_append_length_plus) have ff4: "∀n bs bsa. ((bsa @ bs) ! n::'b) = bs ! (n - length bsa) ∨¬ length bsa ≤ n" using ff2 ff1 by (metis (no_types) add.commute eq_diff_iff nth_append_length_plus) have"∀n na nb. ((n::nat) + nb ≤ na ∨¬ n ≤ na - nb) ∨¬ nb ≤ na" using ff2 ff1 by (metis le_diff_iff) thenhave"(¬ nn < length (ys @ xs) ∨¬ length ys ≤ nn) ∨ P ((ys @ xs) ! nn) ((ys' @ xs') ! nn)" using ff4 ff3 a1 by (metis add.commute length_append not_le) } thenshow ?thesis by blast qed
subsection‹Finding the Index of the First Element of a List Satisfying a Property›
fun find_index :: "('a ==> bool) ==> 'a list ==> nat option"where "find_index f [] = None" | "find_index f (x#xs) = (if f x then Some 0 else (case find_index f xs of Some k ==> Some (Suc k) | None ==> None))"
lemma find_index_index : assumes"find_index f xs = Some k" shows"k < length xs"and"f (xs ! k)"and"∧ j . j < k ==>¬ f (xs ! j)" proof - have"(k < length xs) ∧ (f (xs ! k)) ∧ (∀ j < k . ¬ (f (xs ! j)))" using assms proof (induction xs arbitrary: k) case Nil thenshow ?caseby auto next case (Cons x xs)
show ?caseproof (cases "f x") case True thenshow ?thesis using Cons.prems by auto next case False thenhave"find_index f (x#xs) = (case find_index f xs of Some k ==> Some (Suc k) | None ==> None)" by auto thenhave"(case find_index f xs of Some k ==> Some (Suc k) | None ==> None) = Some k" using Cons.prems by auto thenobtain k' where"find_index f xs = Some k'"and"k = Suc k'" by (metis option.case_eq_if option.collapse option.distinct(1) option.sel)
have"k < length (x # xs) ∧ f ((x # xs) ! k)" using Cons.IH[OF ‹find_index
by auto
moreover have "(∀j<k. ¬ f ((x # xs) ! j))"
using Cons.IH[OF ‹find_index f xs = Some k'›] ‹k = Suc k'› False less_Suc_eq_0_disj
by auto
ultimately show ?thesis by presburger
qed
qed
then show "k < length xs" and "f (xs ! k)" and "∧ j . j < k ==>¬ f (xs ! j)" by simp+
find_index_exhaustive :
assumes "∃ x ∈ set xs . f x"
shows "find_index f xs ≠ None"
using assms proof (induction xs)
Nil
then show ?case by auto
case (Cons x xs)
then show ?case by (cases "f x"; auto)
‹List Distinctness from Sorting›
non_distinct_repetition_indices :
assumes "¬ distinct xs"
shows "∃ i j . i < j ∧ j < length xs ∧ xs ! i = xs ! j"
by (metis assms distinct_conv_nth le_neq_implies_less not_le)
non_distinct_repetition_indices_rev :
assumes "i < j" and "j < length xs" and "xs ! i = xs ! j"
shows "¬ distinct xs"
using assms nth_eq_iff_index_eq by fastforce
ordered_list_distinct :
fixes xs :: "('a::preorder) list"
assumes "∧ i . Suc i < length xs ==> (xs ! i) < (xs ! (Suc i))"
shows "distinct xs"
-
have "∧ i j . i < j ==> j < length xs ==> (xs ! i) < (xs ! j)"
proof -
fix i j assume "i < j" and "j < length xs"
then show "xs ! i < xs ! j"
using assms proof (induction xs arbitrary: i j rule: rev_induct)
case Nil
then show ?case by auto
next
case (snoc a xs)
show ?case proof (cases "j < length xs")
case True
show ?thesis using snoc.IH[OF snoc.prems(1) True] snoc.prems(3)
proof -
have f1: "i < lengthxs"
using True less_trans snoc.prems(1) by blast
have f2: "∀ is then (is @ isa) ! n
= (is ! n::integer) else (is @ isa) ! n = isa ! (n - length is)"
by (meson nth_append)
then have f3: "(xs @ [a]) ! i = xs ! i"
using f1
by (simp add: nth_append)
xs ! j"
using f2
mts uc_lssD ‹ xs ! i < xs ! j›
butlast_snoc length_append_singleton less_SucI nth_butlast snoc.prems(3))
then show ?thesis
then sow ase prof (cses (?f x) x"
by (simp add: nth_append)
qed
next
case False
then have "(xs @ [a]) ! j = a"
using snoc.prems(2)
by (metis length_append_singletonles_ucE nth_pedlenth)
sider=" |">1
using ‹i < j›
by linarith
case 1
then have "i = 0" and "j = Suc i" using \< then
then show ?thesis
thenS x)\inset xs} else None) x') a"
using snoc.prems(2) by blast
next
case 2
then consider "i < j - 1" | "i = j - 1" using ‹i < j› by linarith+
then show ?thesis proof cases
case 1
have "(∧ lookup_with_default f {}"
using snoc.IH[OF 1] snoc.prems(2) 2 by simp
then have le1: "(xs @ [a]) ! i < (if)
set_s_map_containment :
by (metis "2" False One_nat_def Suc_diff_Suc Suc_lessD diff_zero snoc.prems(3)
moreover have le2: "(xs @ [a]) ! (j -1) < (z. (x, z) ∈ xs} else None of None ==> xs)"
using snoc.prs2,3
by (metis (full_types) One_nat_def Suc_diff_Suc diff_zero less_numeral_extra(1))
ultimately show ?thesis
using less_trans by blast
next
ase 2
hve "=Suc i"\<pen1 by linarth
then sow ?thesi
using snoc.prems(3)
using snoc.prems(2) b ls
qed
qed
qed
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
qed
then show ?thesis
by (metis less_asym non_distinct_repetition_indices)
nct_reve
fixes xs :: "('a::preorder) list"
assumes "∧eap_elem :t ∈ x ∈ t = g x"
shows "distinct xs"
-
have "∧
s.ems(1) yao
fix i :: nat
assume a1: "Suc i < length
obtain nn :: "nat ==> n"wher
"∀v2. x1 = Suc v2 ∧) = (x1 = Suc (nn x0 x1) ∧ nn x0 x1 < x0then show False
by mou.pems1 by auto
e f2: "\<n n < Suc nn na n < na ∧ na ∨ n ≠ (∀ Suc nb ∨ nb < naEnumerating Lists› nat 'a list bycaseNil have f3 usingpd Suc_diff_Suc have"h using a1"subseteq> set thenhave"i < length xs" by simp"set sts_of_lengthxs k) ) = {xs' .legth xs' k \<nd set xs}" then using f3 f2 a1 by (metis (no_types) assms diff_less length_rev not_less_iff_gr_or_eqhjava.lang.StringIndexOutOfBoundsException: Index 99 out of bounds for length 99 qed then using ordered_list_distinct[of "rev xs"] by blast thenshow ?thesis qed
lemma et[[ m yastforce "set (suffixes xs) have"!h proof (induction xs) case Nil thenshow ?caseby auto next case (Cons<union> tap (zip
hen*: "set (suffixes (x#xs)) = {zs . ∃ cases ";auto
uto
have"{zs . ∃ by force then have "{zs . ∃existsbs . length bs = length ms ∧ set xs = set (map fst snd) by (metis wse moreovers{ ∃ ys = []}" by f r\opena ∈ set ms› ms" and"ms ! i = a"
ultimatelyshow ?caseusing * by force have"set ( (map s iler n (zm?)) ={s! i |i. i < length ?bs ∧bs ! i}" qed
lemma prefixes_set : "set (prefixes xs) = {xs' . ∃ proofinduction case N then show ?case by auto next case (Cons x xs) moreover have "prefixes (x#xs) = [] # map ((#) x) (prefixes xs)" by auto ultimately have *: "set (prefixes (x#xs)) = insert [] (((#) x) ` {xs'. ∃ {ms ! j |j. j < length j ≠ bs ! j}" by auto also ve "\dots = {xs' . ∃'xs'= x#s)}" proof show "insert [] ((#) x ` {xs'. ∃ ' xs {xs'. ∃xss @xs xs by auto show"{xs'. ∃xs''. xs' @ xs'' = x # xs} ⊆xs''. xs' @ xs'' = xs})" proof fixix"y \in.\existsx''. xs' @ xs'' = x # xs}" thenobtain y' where"y@y' = x #x by blast then show "y ∈sertxs''. xs' @ xs by (cases utojava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26 qed qed finallyshow ?case . qed
fun <> generate_choices "is_prefix [] _ = True" | "(nd (hd cs)= Nn∨find_remove_2_all' P xs ys = "is_prefix (x#xs) (y#ys) = (x = y ∧ is_prefix xs ys)"
lemma is_prefix_prefix : "is_prefix xs proofbitraryys case Nil thenshowusing21byfastforce next case showroofrefix#sjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48 case True thenshow ?thesis using Cons.IH by (metis append_Cons is_prefix.simps(2) is_prefix.simps(3) neq_Nil_conv) next case False thenshow ? using Cons.IHmoreoverhave<> etsxyss qed qed the (snd set (snd xys
un add_prefixesist 'a list list" where "add_prefixes s=oncatefixes
lemma add_prefixes_set : "set (add_prefixes xs) = {xs' . ∃ xs'' . xs'@xs'' ∈ set xs}" proof - have"set (add_prefixes xs) = {xs' . ∃ x ∈ unfolding add_prefixes.simps by auto ave ">= {xs' . ∃ set xs}" proof (induction xs) case Nil then show ?case using preixeset y aut next case (Cons a xs) then show ?case proof f- have "java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34 ⟷ xs' ∈ proof - fix xs' show"xs' ∈i<length xs. P (xs ! i) (xs' ! i)" ⟷ xs' ∈ {xs'. ∃xs''. xs' @ xs'' ∈ set (a # xs)}" unfolding prefixes_set by force qed hen n show ths y blast qed ed finally show ?thesis by blast qed
lemma prefixes_set_ob : assumes "xs\>P ((ys @ xs) ! nn) ((ys' @ xs') ! nn)" obtains xs' where "xss = xs byblast using assms unfolding prefixes_set by auto
lemma prefixes_finite : "finite { x ∈ by (me= (enngth cs = lnt xys
lemmaprefixes_set_Cons_insert "(efixes) = tinsert'[xy( (refixes unfolding prefixes_set proof case" < set (generate_choices (xys#xyss)) then sho ?ce by (ato;siimp dd apped_eqoscnv next case (snoc x xs) then show ?case by (auto; metis (no_types, opaque_lifting) butlast.simps(2) butlast_append butlast_snoc) qed
lemma prefixes_set_subset: "set (prefixes set (prefixes unfolding prefixes_set by auto
lemma prefixes_prefix_subset : assumes"xs ∈ shows "set (prefixes xs) ⊆ set (prefixes ys)" using assms unfolding prefixes_set by auto
lemma prefixes_butlast_is_prefix : " unfolding prefixes_set by (metis (mono_tags, lifting None < the
lemma prefixes_take_iff :
<> et>take (length xs s proof show"xs ∈ s_set by (simp add: append_eq_conv_conj)
show "take (length (snd x = None unfoldingby by (metis (mono_tags, lifting) append_take_drop_id mem_Collect_eq) qed
lemma prefixes_prefixes : assumes
s \>tsetsxs shows proof\ cs ∈ set (generate_choices (xys#xyss))" =tk lg s " let ?zs = " assume "¬(ys>list.set (prefixes zs) ∨ list.set (prefixes ys))" en ve"s🚫
ngt+ moreoverhave vend_indexfof<>Some>None) = Some k" using assms by (metis linear min.commute prefixes_take_iff ultimately show False by moreover have "\><k. ¬ qed
lemmaprefixes_butlast: "set(butlast(prefixesxs))={ys.\<exists>zs.ys@zscasejava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14 proof(induction"lengthxs"arbitrary case0 thenshow?casebyauto next case
thenobtainxxs'where"xs=x#xs'"and"k=lengthxs'" by">i.ilengthxs\<Longrightarrow>xs!i<xs!Suci)\<Longrightarrow>xs!i<xs!(jjava.lang.StringIndexOutOfBoundsException: Index 125 out of bounds for length 125
thenhave"prefixesxs=[]#map((#)x)(prefixesxs')" byauto thenhave"butlast(prefixesxs)=[]#mapff_lessesslength_revrevess_iff_gr_or_eq by(simpadd:map_butlast) thenhave"set(butlast(prefixesxs))=insert[](((#)x)`{ys.\<exists>zs.ys@zs{\existsys.ys@zs=xs}={zs.\<exists>ys.x#ys@zs=x#xs}" usingSuc.hyps(1)[OF byauto alsohave"\<dots>={ys.\<exists>zs.ys@zs=(x#lse proof show"insert[]((#)x{<zs.ys@zssandzs\<noteq>[]})\<subseteq>{ys.\<exists>zss@s\and>zs\<noteq>[]}" byauto show"{ys(tisllect_mem_eqstinite_set_e_Collect_conjI proof e<in{ys.\<exists>zs.ys@zs=x#xs'\andzs\<noteq>[]}" thenshow"ys\<in>insert[]((#)x`{ys.\<exists>zs.ys@zsassumesxs>set(prefixesys)" qed qed finallywe unfolding\<open>xs=x#xs'\<close>. qed
have"set(prefix_pairsxs)={(zsbyases"x"to) usingsnoc.IHbyassumption thenhave"set(prefix_pairsxs)={(zs,ys)|zsys.\<exists>s1xs2.zs@s11\<>s@xs2[xs@<ndxs1\<noteq>[]}" to alsohave.=syss.\<existsxs1xs2.zs@xs1=ys\<and>ys@xs2=xs@[x]\<and>xs1\<noteq>[\and>xs2\<noteq>[]}" proof- let?P1="\<lambda>zsys.(\<exists>xs1xs2.zs@ultimatelyesisjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28 let?P2="\<lambda>zsys.(\
have"\<And>yszs.?P2zsys\<Longrightarrow>?P1zsys" by(metisappend_assocbutlast_appendbutlast_snoc) thenhave"\<And>yszs.?P1yszs=?P2yszs" byblast thenshowhesisyrce qed finallyhave"set(prefix_pairsxs)={(zs,ys)|zsys.\thenhave
lemmaprefixes_Cons: assumes"(x#xsnoteq shows"x=y"and"xs\<in>non_sym_dist_pairs_elems_distinct proof- show"x by(metisCons_eq_appendIassmsnth_Cons_0prefixes_set_ob) show"xs\<in>set(prefixesys)" proof- obtainxs'xs''where"(x#xs)=xs'"and"(y#ys)=xs'@xs''" by(mesonassmsprefixes_set_ob) thenhave"xs'=x#tlxs'" byauto thenhave"xs=tlxs'" using\<open>(x#xs)=xs'\<close>byauto moreoverhave"ys=(tlxs')@xs''" using\<open>(y#ys)=xs'@xs''\<close>\<open>xs'=x#tlxs'\<close> by(metisappend_Conslist.inject) ultimatelyelythesisjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28 unfoldingprefixes_setbyblast qed qed
lemmaprefixes_prepend: assumes"xs'\<in>set(prefixesxs)" shows"xs<>etfixesysjava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45 proof- obtainxs''where"xs=xs'@xs''" usingprefixes_set_obbyauto thenhave"(ys@xs)=(ys@xs')@xs''" byauto thenshow?thesis unfoldingprefixes_setbyauto qed
proof(inductionbarbitrary:a) caseNilandlengthxs"and"ny<lengthxs" thenshow?case unfoldingprefixes_set byfastforce next case(Consxxs) show?caseproof(casesa) caseNil thenshow?thesis by(metisCons.prems(2)list.size(3)prefixes_take_ifftake_eq_Nil) next case(Consa'as) thenhave"a'#as\<in>set(prefixes"upsxs=java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24 usingCons.prems(1)byauto have"a'=x"and"as\<in>set(prefixes(xs@c))" usingprefixes_Cons[OF\<open>a'#as\<in>set(prefixes(x#(xs@c)))\<close>] byauto moreoverhave"as\<notinalsohave""<dots={xs\innth_eq_iff_index_eq using\<open>a\<notin>set(prefixes(x#xs))\<close>unfoldingCons\<open>a'=x\<close>prefixes_setbyauto ultimately and"as=xs@c'" and"c'\<noteq>[]" xy<>et(ear_order_from_list_position thenhave"c=c'@c''"and"a=(x#xs)@c'"and"c'\<noteq>[]" yauto thenshow?thesis usingthatbyblast qed qed thenshow?thesisusingthatbyblast qed
funnon_sym_dist_pairs'::"'alist\<Rightarrow>('a\<times>'a)list"where "non_sym_dist_pairs'[]=[]"| "non_sym_dist_pairs'(x#xs)=(map(\<lambda>y.(x,y))java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
consider(a)"(x,y)\<in>set(map(Pairz)zs)"| (b)"(x,y)\<in>set(non_sym_dist_pairs'zs)" using\<open>(x\existsxs''.find_remove_2Pxsys=me(ys) thenshow?caseproofcases find_remove_set(23))[F*java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40 thenhave"x=z"byauto thenhave"(y,x)\<notin>set(map(Pairz)zs)" open>\<noteq>y\<close>byauto moreoverhave"x\<notin>setzs" using\<open>x=z\<close>\<open>distinct(z#zs)usingremove_2set)OF*Nonef ultimatelyshow?thesis usinghave"Suc<(x'#xs)" next caseb thenhave"x\<noteq>z"and"y\<noteq>z" usingCons.premsunfoldingnon_sym_dist_pairs'.simps by(mesondistinct.simps(2)non_sym_dist_pairs'_elems_distinct(1,2))+ thenshow?thesis usingCons.IH[OF\<open>distinctzs\<close>b]byauto qed qed
lemmanon_sym_dist_pairs_elems_non_refljava.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 assumes"(x,y)\<in>set(non_sym_dist_pairsxs)" shows"(y,x)\<notin>set(non_sym_dist_pairsxs)" usingassmsby(simpadd:non_sym_dist_pairs'_elems_non_refl)
lemmalinear_order_from_list_position_refl: "refl_on(setxs)(set(linear_order_from_list_positionxs))" proof(rulerefl_onI) <And>x\\<>setxs\<Longrightarrow>(x,x)\<in>set(linear_order_from_list_positionxs" unfoldinglinear_order_from_list_position_set usingnon_sym_dist_pairs_subset[ofxs]byauto qed
lemmalinear_order_from_list_position_antisym: "antisym(set(linear_order_from_list_positionxs))" proof fixxyassume"(x,y)\<in>t(linear_order_from_list_positions simp thenhave"(x,y)\<in>set(map(\<lambda>x.(x,x))xs)\<union>set(non_sym_dist_pairsxs)have"forallp(\<lambda>pa.\<not>(casepaofabption)<>p<>(a,z).\<not>pz)" and"(y,x)\<in>set(map(\<lambda>x.(x,x))xs)\<union>set(non_sym_dist_pairsxs)" unfoldinglinear_order_from_list_position_setbyblast+ thenconsider(a)"(x,y)\<in>set"\<>ys.<>tetpow_list_ist#sjava.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63 (b)"(x,y)\<in>set(non_sym_dist_pairsxs)" byblast thenshow"x=y" proofcases casea thenshow?thesisbyauto next caseb thenhave"x\<noteq>andy<set(non_sym_dist_pairsxs)" usingnon_sym_dist_pairs_set_iff[ofxyxs]bysimp+ thenhave"(y,x)\<notin>set(map(\<lambda>x.(x,x))xs)\<union>set(non_sym_dist_pairsxs)"
java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 13 wsis using\<open>(y,x)\<in>set(map(\<lambda>x.(x,x))xs)\<union>set(non_sym_dist_pairsxs)\<close>byblast qed qed
thenshow?thesis using\<open>(a#xs)!0=x\<close>\<open>0<length(a#xs)\<close>byblast next caseFalse thenhave"(x,y)\<in>set(non_sym_dist_pairs'xs)" usingCons.prems(2)byauto thenshow?thesis usingCons.IHCons.prems(1) byhave"remove_subsets=ove_subsets#lter\<lambday.\<not>(y\<subseteq>)xs) qed qed
obtainnxnywhere"xs!nx=x"and"xsnyndnx" and"nx<lengthxsdnylengthxs" usingnon_sym_dist_pairs'_indices[OF\<open>distinctxs\<close>\<open>(x,y)\<in>set(non_sym_dist_pairs'xs)\<close>] last
have"\<not>(z,x)\<in>set(non_sym_dist_pairs'xs)" proof assume"(z,x)\<in>set(non_sym_dist_pairs'xs)" thenobtainnz'nite and"nx'<lengthxs"and"nz'java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 usingnon_sym_dist_pairs'_indices[OF\<open>distinctxs\<close>,ofzx]bymetis
have"nx'=nx" using\<open>distinctxs\<\And>.<nxs\<Longrightarrow>y\<in>xs\<Longrightarrow>assign_indicesxsx=assign_indicesxsy\<Longrightarrow>x=y" nth_eq_iff_index_eq bymetis moreoverhave"nz'=nz" using\<open>distinctxs\<close>\<open>xs!nz=zproof- nth_eq_iff_index_eq bymetis ultimatelyhave"nz<nx" using\<open>nz'<nx'\<close>byauto using\<open>nx<nz\<close>bysimp qed thenshow"(x,z)\<in>set(non_sym_dist_pairs'xs)" usingnon_sym_dist_pairs'_elems_distinct(1)[OF\<open>distinctxs\<close>\<open>(x,y)\<in>set(non_sym_dist_pairs'xs)\<close>] non_sym_dist_pairs'_elems_distinct(2)[OF\<open>distinctxs\<close>\<open>(y,z)\<in>set(non_sym_dist_pairs'xs)\<close>] \<openultimately?thesis non_sym_dist_pairs_elems[ unfoldingon_sym_dist_pairs\remdupsxs=xs\<close> byblast qed
lemmalinear_order_from_list_position_trans:"trans(set(linear_order_from_list_positionxs))" proof fixxyzassume"(x,y)\<in>set(linear_order_from_list_positionxs)"anddistinctas_list_helperXjava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37 and"(y,z)\<in>set(linear_order_from_list_positionxs)" thenconsider(a)"(x,y)\<in>set(map(\<by(metisas_list_helper_def"xs\noteq>" (b)"(x,y)\<in>set(map(\<lambda>x.(x,x))xs)\<and>(y,z)\<in>set(non_sym_dist_pairsxs)"| (c)"(x,y)\<in>set(non_sym_dist_pairsxs)\<and>(y,z)\<in>set(map(\<lambda>x.shows\exists\<in>xs.\<not>(\<exists>y\<in>xs.lengthy<lengthx)" (d)"(<>(non_sym_dist_pairsist_pairs_sxs<and(y,z)\<in>set(non_sym_dist_pairs) unfoldinglinear_order_from_list_position_setbyblast+ thenshow"(x,z)\<in>set(\>caseSucj) proofcases thenshow?thesisunfoldinglinear_order_from_list_position_setbyauto next caseb thenshow?thesisunfoldinglinear_order_from_list_position_setbyauto next casec isfoldinglinear_order_from_list_position_set next cased thenshow?thesisunfoldinglinear_order_from_list_position_set using (java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 13 qed qed
funfind_remove'::"('a\<Rightarrow>bool)\<Rightarrow>'alist\<Rightarrow>'alist\<Rightarrow>('a\<times>'alist)optionjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 "find_remove'P[]_=None"| "find_remove'P(x#xs)prev=(ifPx thenSome(x,prev@xs) elsefind_remove'Pxs(prev@[x]))"
lemmafind_remove'_set: ingfind_index_index)[F\open>(=)y)(sorted_list_of_setxs)Somei<close>java.lang.StringIndexOutOfBoundsException: Index 101 out of bounds for length 101 shows"Px" and"x\<in>setxs" and"xs'=prev@(remove1xxs)" proof- have"Px\<and>x\<in>setxs\<and>xs'=prev@(remove1xxs)" usingassmsproof(inductionxsarbitrary:prevxs') caseNil thenshow?casebyauto next case(Consxxs) show?caseproof(cases"Px") True thenshow?thesisusingConsbyauto next casealse thenshow?thesisusingConsbyfastforce qed qed thenshow"Px" and"x\<in>setxs" and"xs'=prev@(remove1xxs)" byblast+ qed
lemmafind_remove'_set_rev: assumes"x\<in>setxs" and"Px" shows"find_remove'Pxsprev\<noteq>None" usingassms)oofnductionitraryrev caseNil thenshow?casebyauto next case<>(ngth=ucard)close>by(simpadd:distinct_card) show?caseproof(cases"Px") caseTrue ?hesisusingConsbyauto next caseFalse thenshow?thesisusingCons usingassms(2)byauto qed qed
funfind_remove_2'::"('a\<Rightarrow>'b\<Rightarrow>bool)\<Rightarrow>'alist\<Rightarrow>'blist\<Rightarrow>'alist\<Rightarrow>('a\<times>'b\<times>'alist)option" where "find_remove_2'P[]__=None"| False Somey\<Rightarrow>Some(x,y,prev@xs)| None\<Rightarrow>find_remove_2'Pxsys(prev@[x]))"
funfind_remove_2::"('a\<Rightarrow>'b\<Rightarrow>bool)\<Rightarrow>'alist\<Rightarrow>'blist\<Rightarrow>('a\<times>'b\<times>'alist)option"where d_remove_2sfind_remove_2Pys]java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
lemmafind_remove_2'_set: assumes"find_remove_2'Pxsysprev=Some(x,y,xs')" shows"Py and"x\<in>setxs" and"y\<inetys and"distinct and"distinct(prev@xs)\<Longrightarrow>distinctxs'" and"xs'=prev@(remove1xxs)" proof- have"Pxy \<and>x\<in>setxs \<and>y\<in>setys \<and>(distinct(prev@xs)bysimp \<and>(distinct(prev@xs)\<longrightarrow>distinctxs') \<and>(xs'=prev@(remove1xxs)) \<and>find(Px)ys=Somey" usingassms proof(inductionxsarbitrary:prevxs'xy) caseNil thenshow?casebyauto next case(Consx'xs) thenshow?caseproof(cases"find(\<lambda>y.Px'y)ys") caseNone thenhave"find_remove_2'P(x'#xs)ysprev=find_remove_2'Pxsys(prev@[x'])" usingCons.prems(1)byauto hence*:"find_remove_2'Pxsys(prev@[x'])=Some(x,y,xs')" usingCons.prems(1)bysimp have"x'\<noteq>x" by(metis"*"Cons.IHNonefind_from) moreoverhave"distinct(prev@x'#xs)\<longrightarrow>distinct((x'#prev)@xs)" byauto ultimatelyshow?usingCons.IH[OF] byauto next "xsjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21 thenhave"find_remove_2'P(x'#xs)ysprev=Some(x',y',prev@xs)" byauto thenshow?thesisusingSome singsems)nd_condition_yastforce qed thenshowthenshowalsee" and"x\<in>setxs" (insert) "distinctprevevxs\ongrightarrow>setxs'=then?proof("{"java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40 and"distinct(prev@xs)\<Longrightarrow>distinctxs'" and"xs'=prev@(remove1xxs)" findx)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 byblast+ qed
lemmafind_remove_2'_strengthening: assumes"find_remove_2'Pxsysprev=Some(x,y,xs')" and"P'xy" and"\<And>x'y'ympard_mono shows"find_remove_2'P'xsysprev=Some(x,y,xs')" usingassmsproof(inductionxsarbitrary:prev) caseNil thenshow?casebyauto next case(Consx'xs) thenshow?caseproof(cases"find(\<lambda>y.Px'y)ys") caseNone thenshow?thesisusingCons by(metis(mono_tags,lifting)find_None_ifffind_remove_2'.simps(2)option.simps(4)) next case(Somea) thenhave"x'=x"and"a=y" usingCons.prems(1)unfoldingfind_remove_2'.simpsby thenhave"find(\<lambda>y.Pxy)ys=Somey" usingfind_remove_2'_set[OFCons.prems(1)]byauto thenhave"find(\<lambda>y.P'xy)ys=Somey" usingCons.prems(3)proof(inductionys) caseNil nwcaseuto next case(Consy'ys) thense by(metisassms(2)find.simps(2)option.inject) qed thenshow?thesis usingfind_remove_2'_set(6)[OFCons.prems(1)] unfolding\<open>x'=x\<close>find_remove_2'.simpsbyauto qed qed
lemmafind_remove_2'_prev_independence: assumes"find_remove_2'Pxsysprev=Some(x,y,xs')" shows"\<exists>xs''.find_remove_2'Pxsysprev'=Some(x,y,xs'')" usingassmsproof(inductionxsarbitraryprevprev'xs) caseNil thenshow?casebyauto next case(Consx'xs) show?caseproof(cases"find(\<lambda>y.Px'y)ys") caseNone thenshow?thesis usingCons.IHCons.premsbyauto next case(Somea) thenshow?thesisusingConspremsunfoldingfind_remove_2'.simps bysimp qed
lemmafind_remove_2'_filter: assumes"find_remove_2'P(filterP'xs)ysprev=Some(x,y,xs')" and"\<And>xy.\<not>P'x\<Longrightarrow>\<not>Pxy" shows"\<exists>xs''.find_remove_2'Pxsysprev=Some(x,y,xs'')" usingassms(1)proof(inductionxsarbitrary:prevprevxs') caseNil thenshow?casebyauto next case(Consx'xs) thenshow?caseproofand"(\<Union<nX.px)=X" caseTrue thenhave*:"find_remove_2'P(filterP'(x'#xs))ysprev =find_remove_2'P(x'#filterP'xs)ysprev" byauto show?thesisproof(cases"find(\<lambda>y.Px'y)ys") caseNone howsis emsemove_2)onps)java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80 next case(Somehave"\lambdan.set(as_list_helper(lambda>s_list_helperelperpn`).`l" thenhave"x'=x"and"a=y" usingCons.qed unfoldingunfolding*find_remove_2'.simpsbyauto show?thesis usingSome unfolding\<open>x'=x\<close>\<open>a=y\<close>find_remove_2'.simps bysimp qed next caseFalse have"find_remove_2'P(Pxssprevev=e,s" usingCons.premsbyauto
fromFalseassms(2)have"find(\<>.Px'y)ys=None" by(simpadd:find_None_iff) thenhave"find_remove_2'P(x'#xs)ysprev=find_remove_2'Pxsys(prev@[x'])" byauto wthesis n>find_remove_2'P(ilterP)ysprev=Some(x,yy,s')\close]java.lang.StringIndexOutOfBoundsException: Index 96 out of bounds for length 96 unfolding\<open>find_remove_2'P(x'#xs)qed usingfind_remove_2'_prev_independencebymetis qed qedthenshowyuto
lemmafind_remove_2'_set_rev: <insetxs" and"y\<in>setys" and"Pxy" shows"find_remove_2'Pxsysprev\<noteq>None" usingassms(1)proof(inductionxsarbitrary:prev) caseNil then"?ssSuc)" next case(Consx'xs) thenshow?caseproof(cases"findjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 caseNone thenhave"x\<noteq>x'" usingassms(2,3)by(metisfind_None_iff) thenhave"x\<in>setxs" usingCons.premsbyauto show? usingCons.IHunfoldingfind_remove_2'.simpsNonebyauto next case(Somea) thenshow?thesisbyauto qed qed
lemmafind_remove_2'_diff_prev_None: "(find_remove_2'Pxsysprev=None\<Longrightarrow>find_remove_2'Pxsysprev'=None)" proof(inductionxsarbitrary:prevprev') caseNil thenshow?casebyauto next case(Consxxs) show?caseproof(cases"find(\<lambda>y.Pxy)ys") caseNone thenjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 and"find_remove_2'P(x#xs)ysprev'=find_remove_2'Pxsys(prev'@[x])" byauto thenhowhesissingto next case(Somea) thenshow?thesisusingConsbyauto qed qed
lemmafind_remove_2'_diff_prev_Some: "(find_remove_2'Pxsysprev=Some(x,y,xs') \<Longrightarrow>\<exists>xs''.find_remove_2'Pxsysprev'=Some(x,y,xs''))" proof(inductionxsarbitrary:prevprev') caseNil thenshow?casebyauto next case(Consxxs) show?caseproof(cases"find(\<lambda>y.Pxy)ys") caseNone thenhave"find_remove_2'P(x#xs)ysprev=find_remove_2'Pxsys(prev@[x])" and"find_remove_2'P(x#xs)ysprev'=find_remove_2'Pxsys(prev'@[x])" byauto thenthenshow?thesisusingConsbyauto next case(Somea) thenshow?thesisusingConsbyauto qed qed
java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 30 "find_remove_2Pxsys=None\<longleftrightarrow>\<not(<exists>xy.x\<in>setxs\<and>y\<in>setys\<and>Pxy)" unfoldingfind_remove_2.simps usingfind_remove_2'_set(1-3)find_remove_2'_set_rev by(metisold.prod.exhaustoption.exhaust)
have"(filterPxs,filter(\<lambda>x.\<not>Px)xs)=foldr?fxs([],[])" usingCons.IHbyauto moreoverhave"separate_byP(a#xs)=?fa(filterPxs,filter(\<lambda>x.\java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 byauto ultimatelyshow?case by(cases"Pa";auto) qed
have"lengthxs'=lengthxs-1" usingfind_remove_set(2,3)[OF\<open>find_remove((\<subset>)x)xs=Some(y',xs')\<close>] by(simpadd:length_remove1) thenhave"length(y'#xs')=lengthxs" usingfind_remove_set(2)[OF\<open>find_remove((\<subset>)x)xs=Some(y',xs')\<close>] usingremove1_lengthbyfastforce have"length(filter(\<lambda>y.\<not>y\<subseteq>x)xs')\<le>lengthxs'" bysimp thenhave"length(y'#filter(\<lambda>y.\<not>y\<subseteq>x)xs')\<le>lengthxs'+1" bysimp thenhave"length(y'#filter(\<lambda>y.\<not>y\<subseteq>x)xs')\<le>lengthxs" unfolding\<open>length(y'#xs')=lengthxs\<close>[symmetric]bysimp thenshow"(y'#filter(\<lambda>y.\<not>y\<subseteq>x)xs',x#xs)\<in>measureor>fS1<>=}java.lang.StringIndexOutOfBoundsException: Index 124 out of bounds for length 124 byauto qed ultimatelyshow?thesis by(relation"measurelength";auto) qed
thenhave"xs\<in>set(y'#filter(\<lambda>y.\<not>y\<subseteq>x)xs')" usingfind_remove_set[OF*] by(metisfilter_list_setin_set_remove1list.set_intros(1)list.set_intros(2)psubsetIset_ConsD) moreoverhave"\<nexists>xs'a.xs'a\<in>set(y'#filter(\<lambda>y.\<not>y\<subseteq>x)xs')\<and>xs\<subset>xs'a" using\<open>xs\<in>set(x#xss')\<close>\<open>\<nexists>xs'.xs'\<in>set(x#xss')\<and>xs\<subset>xs'\<close>find_remove_set[OF*] by(metisfilter_is_subsetlist.set_intros(2)notin_set_remove1set_ConsDsubset_iff) ultimatelyshow"xs\<in>{xs\<in>set(y'#filter(\<lambda>y.\<not>y\<subseteq>x)xs').\<nexists>xs'a.xs'a\<in>set(y'#filter(\<lambda>y.\have"fx=x byblast qed ultimatelyshow?thesisbyblast qed finallyshow?thesisunfoldingConsbyassumption qed qed qed
have"\<And>zs.(\<nexists>ys.ys\<noteq>[]\<and>zs@ys\<in>(setxs))=(\<forall>ys\<in>setxs.is_prefixzsys\<longrightarrow>zs=ys)" unfoldingis_prefix_prefixbyauto thenshow?thesis unfolding*filter_setbyauto qed
lemmafilter_length_weakening: assumes"\<And>q.f1q\<Longrightarrow>f2q" shows"length(filterf1p)\<le>length(filterf2p)" proof(inductionp) caseNil thenshow?casebyauto next case(Consap) thenshow?caseusingassmsby(cases"f1a";auto) qed
lemmamax_length_elem: fixesbyblast assumes"finitexs" and"xs\<noteq>{}" shows"\<exists>x\<in>xs.\<not>(\<exists>y\<in>xs.lengthy>lengthx)" usingassmsproof(inductionxs) caseempty thenshow?casebyauto next case(insertxF) thenshow?caseproof(cases"F={}") caseTrue thenshow?thesisbyblast next caseFalse thenobtainywhere"y\<in>F"and"\<not>(\<exists>y'\<in>F.lengthy'>lengthy)" usinginsert.IHbyblast thenshow?thesisusingdual_order.strict_transby(cases"lengthx>lengthy";auto) qed qed
lemmamin_length_elem: fixesxs::"'alistset" assumes"finitexs" and"xs\<noteq>{}" shows"\<exists>x\<in>xs.\<not>(\<exists>y\<in>xs.lengthy<lengthx)" usingassmsproof(inductionxs) caseempty thenshowlemmasum_image_inj_card_helper: next case(insertxF) thenshow?caseproof(cases"F={}") caseTrue thenshow?thesisbyblast next caseFalse thenobtainywhere"y\<in>F"and"\<not>(\<exists>y'\<in>F.lengthy'<lengthy)" usinginsert.IHbyblast thenshow?thesisusingdual_order.strict_transby(cases"lengthx<lengthy";auto) qed qed
lemmarev_induct2[consumes1,case_namesNilsnoc]: assumes"lengthxs=lengthys" and"P[][]" and"(\<And>xxsyys.lengthxs=lengthys\<Longrightarrow>Pxsys\<Longrightarrow>P(xs@[x])(ys@[y]))" shows"Pxsys" usingassmsproof(inductxsarbitrary:ysrule:rev_induct) caseNil thenshow?casebyauto next case(snocxxs) thenshow?caseproof(casesys) caseNil thenshow?thesis usingsnoc.prems(1)byauto next case(Consalist) thenshow?thesis by(metisappend_butlast_last_iddiff_Suc_1length_append_singletonlist.distinct(1)snoc.hypssnoc.prems) qed qed
lemmafinite_set_min_param_ex: assumes"finiteXS" and"\<And>x.x\<in>XS\<Longrightarrow>\<exists>k.\<forall>k'.k\<le>k'\<longrightarrow>Pxk'" shows"\<exists>(k::nat).\<forall>x\<in>XS.Pxk" proof- obtainfwheref_def:"\<And>x.x\<in>XS\<Longrightarrow>\<forall>k'.(fx)\<le>k'\<longrightarrow>Pxk'" usingassms(2)bymeson let have"\<forall>x\<in>XS.Px?k" usingf_defby(simpadd:assms(1)) thenshow?thesisbyblast qed
have**:"\<And>i(ss::'asetlist).(\<forall>i<lengthss-1.ss!i\<subset>ss!(Suci))\<Longrightarrow>i<lengthss\<next proof- fixi fixss::"'asetlist" assume"i<lengthss"and"(\<forall>i<lengthss-1.ss!i\<subset>ss!(Suci))" thenshow"\<forall>s\<in>set(takeiss).s\<subset>ss!i" proof(inductioni) case0 thenshow?casebyauto next case(Suci) thenhave"\<forall>s\<in>set(takeiss).s\<subset>ss!i"byauto thenhave"\<forall>s\<in>set(takeiss).s\<subset>ss!(Suci)"usingSuc.prems by(metisOne_nat_defSuc_diff_SucSuc_lessEdiff_zerodual_order.strict_transnat.injectzero_less_Suc) moreoverhave"ss!i\<subset>ss!(Suci)"usingSuc.premsbyauto moreoverhave"(take(Suci)ss)=(takeiss)@[ss!i]"usingSuc.prems(1) by(simpadd:take_Suc_conv_app_nth) ultimatelyshow?casebyauto qed qed
have"distinctss" using\<open>(\<forall>i<lengthss-1.ss!i\<subset>ss!(Suci))\<close> proofinduction:rev_inductjava.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39 caseNil thenshow?casebyauto next case(snocass) fromsnoc.premshave"\<forall>i<lengthss-1.ss!i\<subset>ss!Suci" by(metisSuc_lessDdiff_Suc_1diff_Suc_eq_diff_predlength_append_singletonnth_appendzero_less_diff) thenhave"distinctss" usingsnoc.IHbyauto moreoverhave"a\<notin>setss" using**[OFsnoc.prems,of"length(ss@[a])-1"]byauto ultimatelyshow?casebyauto qed
thenhave"card(setss)=Suc(cardX)" using\<open>(lengthss=Suc(cardX))\<close>by(simpadd:distinct_card) thenshow"False" using\<open>setss\<subseteq>X\<close>\<open>finiteX\<close>by(metisSuc_n_not_le_ncard_mono) qed
lemmamaximal_distinct_prefix: assumes"\<not>distinctxs" obtainsnwhere"distinct(take(Sucn)xs)" and"\<not>(distinct(take(Suc(Sucn))xs))" usingassmsproof(inductionxsrule:rev_induct) caseNil thenshow?casebyauto next case(snocxxs) show?caseproof(cases"distinctxs") caseTrue thenhave"distinct(take(lengthxs)(xs@[x]))"byauto moreoverhave"\<not>(distinct(take(Suc(lengthxs))(xs@[x])))"usingsnoc.prems(2)byauto ultimatelyshow?thesisusingthatby(metisSuc_preddistinct_singletonlength_greater_0_convself_append_conv2snoc.prems(1)snoc.prems(2)) next caseFalse thenshow?thesisusingsnoc.IHthat by(metisSuc_monobutlast_snoclength_append_singletonless_SucIlinorder_not_lesnoc.prems(1)take_alltake_butlast) qed qed
thenshow?thesis unfolding\<open>((\<Union>x\<in>xs.\<Union>(g`fx))\<union>\<Union>(g`fx))=(\<Union>x\<in>(insertxxs).\<Union>(g`fx))\<close>byassumption qed
ultimatelyshow?casebylinarith qed
moreoverhave"card(\<Union>x\<in>xs.(\<Union>y\<in>fx.gy))\<le>cardzs" proof- have"(\<Union>x\<in>xs.(\<Union>y\<in>fx.gy))\<subseteq>zs" usingassms(6)by(simpadd:UN_least) moreoverhave"finite(\<Union>x\<in>xs.(\<Union>y\<in>fx.gy))" by(simpadd:assms(1)assms(4)assms(5)) ultimatelyshow?thesis usingassms(7) by(simpadd:card_mono) qed
thenshow?thesis using\<open>y\<in>F\<close>\<open>gx=gy\<close>byblast qed qed thenshow?thesis usingthatbyblast qed
lemmamonotone_function_with_limit_witness_helper: fixesf::"nat\<Rightarrow>nat" assumes"\<And>ij.i\<le>j\<Longrightarrow>fi\<le>fj" and"\<And>ijm.i<j\<Longrightarrow>fi=fj\<Longrightarrow>j\<le>m\<Longrightarrow>fi=fm" and"\<And>i.fi\<le>k" obtainsxwhere"f(Sucx)=fx"and"x\<le>k-f0" proof- have"\<And>i.f(Suci)\<ge>f0+Suci\<or>(f(Suci)<f0+Suci\<and>fi=f(Suci))" proof- fixi show"f(Suci)\<ge>f0+Suci\<or>(f(Suci)<f0+Suci\<and>fi=f(Suci))" proof(inductioni) case0 thenshow?caseusingassms(1) by(metisadd.commuteadd.left_neutraladd_Suc_shiftle0le_antisymlessInot_less_eq_eq) next case(Suci) thenshow?case proof- have"\<forall>n.n\<le>Sucn" bysimp thenshow?thesis by(metisSucadd_Suc_rightassms(1)assms(2)le_antisymnot_lessnot_less_eq_eqorder_trans_rules(23)) qed qed qed
have"\<exists>x.f(Sucx)=fx\<and>x\<le>k-f0" usingassms(3)proof(inductionk) case0 thenshow?casebyauto next case(Suck) consider"f0+Suck\<le>f(Suck)"|"f(Suck)<f0+Suck\<and>fk=f(Suck)" using\<open>\<And>i.f(Suci)\<ge>f0+Suci\<or>(f(Suci)<f0+Suci\<and>fi=f(Suci))\<close>[ofk] byblast
thenshow?caseproofcases case1 thenhave"f(Suc(Suck))=f(Suck)" usingSuc.prems[of"Suc(Suck)"]assms(1)[of"Suck""Suc(Suck)"] byauto thenshow?thesis by(metis"1"Suc.premsadd.commuteadd_diff_cancel_left'add_increasing2le_add2le_add_same_cancel2le_antisym) next case2 thenhave"f(Suck)<f0+Suck"and"fk=f(Suck)" byauto thenshow?thesis by(metisSuc.prems\<open>\<And>i.f0+Suci\<le>f(Suci)\<or>f(Suci)<f0+Suci\<and>fi=f(Suci)\<close>add_Suc_rightadd_diff_cancel_left'le0le_Suc_exnat_arith.rule0not_less_eq_eq) qed qed
thenshow?thesis usingthatbyblast qed
lemmadifferent_lists_shared_prefix: assumes"xs\<noteq>xs'" obtainsiwhere"takeixs=takeixs'" and"take(Suci)xs\<noteq>take(Suci)xs'" proof- have"\<exists>i.takeixs=takeixs'\<and>take(Suci)xs\<noteq>take(Suci)xs'" proof(ruleccontr) assume"\<nexists>i.takeixs=takeixs'\<and>take(Suci)xs\<noteq>take(Suci)xs'" have"\<And>i.takeixs=takeixs'" proof- fixishow"takeixs=takeixs'" proof(inductioni) case0 thenshow?casebyauto next case(Suci) thenshow?case using\<open>\<nexists>i.takeixs=takeixs'\<and>take(Suci)xs\<noteq>take(Suci)xs'\<close>byblast qed qed have"xs=xs'" by(simpadd:\<open>\<And>i.takeixs=takeixs'\<close>take_equalityI) thenshow"False" usingassmsbysimp qed thenshow?thesisusingthatbyblast qed
thenshow?thesis usingthatusing\<open>?x'\<in>?xs\<close>byblast qed
lemmamap_upds_map_set_left: assumes"[mapfxs[\<mapsto>]xs]q=Somex" shows"x\<in>setxs"and"q=fx" proof- have"x\<in>setxs\<and>q=fx" usingassmsproof(inductionxsrule:rev_induct) caseNil thenshow?casebyauto next case(snocx'xs) show?caseproof(cases"fx'=q") caseTrue thenhave"x=x'" usingsnoc.premsby(inductionxs;auto) thenshow?thesis usingTruebyauto next caseFalse thenhave"[mapf(xs@[x'])[\<mapsto>]xs@[x']]q=[mapf(xs)[\<mapsto>]xs]q" by(inductionxs;auto) thenshow?thesis usingsnocbyauto qed qed thenshow"x\<in>setxs"and"q=fx" byauto qed
lemmamap_upds_map_set_right: assumes"x\<in>setxs" shows"[xs[\<mapsto>]mapfxs]x=Some(fx)" usingassmsproof(inductionxsrule:rev_induct) caseNil thenshow?casebyauto next case(snocx'xs) show?caseproof(cases"x=x'") caseTrue thenshow?thesis by(inductionxs;auto) next caseFalse thenhave"[xs@[x'][\<mapsto>]mapf(xs@[x'])]x=[xs[\<mapsto>]mapfxs]x" by(inductionxs;auto) thenshow?thesis usingsnocFalsebyauto qed 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.0.557Bemerkung:
(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.