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 f xs = Some k'›] ‹k = Suc k'› by auto moreoverhave"(∀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 ultimatelyshow ?thesis by presburger qed qed thenshow"k < length xs"and"f (xs ! k)"and"∧ j . j < k ==>¬ f (xs ! j)"by simp+ qed
lemma find_index_exhaustive : assumes"∃ x ∈ set xs . f x" shows"find_index f xs ≠ None" using assms proof (induction xs) case Nil thenshow ?caseby auto next case (Cons x xs) thenshow ?caseby (cases "f x"; auto) qed
subsection‹List Distinctness from Sorting›
lemma 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)
lemma 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
lemma ordered_list_distinct : fixes xs :: "('a::preorder) list" assumes"∧ i . Suc i < length xs ==> (xs ! i) < (xs ! (Suc i))" shows"distinct xs" proof - have"∧ i j . i < j ==> j < length xs ==> (xs ! i) < (xs ! j)" proof - fix i j assume"i < j"and"j < length xs" thenshow"xs ! i < xs ! j" using assms proof (induction xs arbitrary: i j rule: rev_induct) case Nil thenshow ?caseby auto next case (snoc a xs) show ?caseproof (cases "j < length xs") case True show ?thesis using snoc.IH[OF snoc.prems(1) True] snoc.prems(3) proof - have f1: "i < length xs" using True less_trans snoc.prems(1) by blast have f2: "∀is isa n. if n < length is then (is @ isa) ! n = (is ! n::integer) else (is @ isa) ! n = isa ! (n - length is)" by (meson nth_append) thenhave f3: "(xs @ [a]) ! i = xs ! i" using f1 by (simp add: nth_append) have"xs ! i < xs ! j" using f2 by (metis Suc_lessD ‹(∧i. Suc i < length xs ==> xs ! i < xs ! Suc i) ==> xs ! i < xs ! j›
butlast_snoc length_append_singleton less_SucI nth_butlast snoc.prems(3)) thenshow ?thesis using f3 f2 True by (simp add: nth_append) qed next case False thenhave"(xs @ [a]) ! j = a" using snoc.prems(2) by (metis length_append_singleton less_SucE nth_append_length)
consider "j = 1" | "j > 1" using‹i < j› by linarith thenshow ?thesis proof cases case1 thenhave"i = 0"and"j = Suc i"using‹i < j›by linarith+ thenshow ?thesis using snoc.prems(3) using snoc.prems(2) by blast next case2 then consider "i < j - 1" | "i = j - 1"using‹i < j›by linarith+ thenshow ?thesis proof cases case1
have"(∧i. Suc i < length xs ==> xs ! i < xs ! Suc i) ==> xs ! i < xs ! (j - 1)" using snoc.IH[OF 1] snoc.prems(2) 2by simp thenhave le1: "(xs @ [a]) ! i < (xs @ [a]) ! (j -1)" using snoc.prems(2) by (metis "2" False One_nat_def Suc_diff_Suc Suc_lessD diff_zero snoc.prems(3)
length_append_singleton less_SucE not_less_eq nth_append snoc.prems(1)) moreoverhave le2: "(xs @ [a]) ! (j -1) < (xs @ [a]) ! j" using snoc.prems(2,3) 2 less_trans by (metis (full_types) One_nat_def Suc_diff_Suc diff_zero less_numeral_extra(1)) ultimatelyshow ?thesis using less_trans by blast next case2 thenhave"j = Suc i"using‹1 < j›by linarith thenshow ?thesis using snoc.prems(3) using snoc.prems(2) by blast qed qed qed qed qed
thenshow ?thesis by (metis less_asym non_distinct_repetition_indices) qed
lemma ordered_list_distinct_rev : fixes xs :: "('a::preorder) list" assumes"∧ i . Suc i < length xs ==> (xs ! i) > (xs ! (Suc i))" shows"distinct xs" proof - have"∧ i . Suc i < length (rev xs) ==> ((rev xs) ! i) < ((rev xs) ! (Suc i))" using assms proof - fix i :: nat assume a1: "Suc i < length (rev xs)" obtain nn :: "nat ==> nat ==> nat"where "∀x0 x1. (∃v2. x1 = Suc v2 ∧ v2 < x0) = (x1 = Suc (nn x0 x1) ∧ nn x0 x1 < x0)" by moura thenhave f2: "∀n na. (¬ n < Suc na ∨ n = 0 ∨ n = Suc (nn na n) ∧ nn na n < na) ∧ (n < Suc na ∨ n ≠ 0 ∧ (∀nb. n ≠ Suc nb ∨¬ nb < na))" by (meson less_Suc_eq_0_disj) have f3: "Suc (length xs - Suc (Suc i)) = length (rev xs) - Suc i" using a1 by (simp add: Suc_diff_Suc) have"i < length (rev xs)" using a1 by (meson Suc_lessD) thenhave"i < length xs" by simp thenshow"rev xs ! i < rev xs ! Suc i" using f3 f2 a1 by (metis (no_types) assms diff_less length_rev not_less_iff_gr_or_eq rev_nth) qed thenhave"distinct (rev xs)" using ordered_list_distinct[of "rev xs"] by blast thenshow ?thesis by auto qed
subsection‹Calculating Prefixes and Suffixes›
fun suffixes :: "'a list ==> 'a list list"where "suffixes [] = [[]]" | "suffixes (x#xs) = (suffixes xs) @ [x#xs]"
lemma suffixes_set : "set (suffixes xs) = {zs . ∃ ys . ys@zs = xs}" proof (induction xs) case Nil thenshow ?caseby auto next case (Cons x xs) thenhave *: "set (suffixes (x#xs)) = {zs . ∃ ys . ys@zs = xs} ∪ {x#xs}" by auto
lemma prefixes_set : "set (prefixes xs) = {xs' . ∃ xs'' . xs'@xs'' = xs}" proof (induction xs) case Nil thenshow ?caseby auto next case (Cons x xs) moreoverhave"prefixes (x#xs) = [] # map ((#) x) (prefixes xs)" by auto ultimatelyhave *: "set (prefixes (x#xs)) = insert [] (((#) x) ` {xs'. ∃xs''. xs' @ xs'' = xs})" by auto alsohave"… = {xs' . ∃ xs'' . xs'@xs'' = (x#xs)}" proof show"insert [] ((#) x ` {xs'. ∃xs''. xs' @ xs'' = xs}) ⊆ {xs'. ∃xs''. xs' @ xs'' = x # xs}" by auto show"{xs'. ∃xs''. xs' @ xs'' = x # xs} ⊆ insert [] ((#) x ` {xs'. ∃xs''. xs' @ xs'' = xs})" proof fix y assume"y ∈ {xs'. ∃xs''. xs' @ xs'' = x # xs}" thenobtain y' where"y@y' = x # xs" by blast thenshow"y ∈ insert [] ((#) x ` {xs'. ∃xs''. xs' @ xs'' = xs})" by (cases y; auto) qed qed finallyshow ?case . qed
fun is_prefix :: "'a list ==> 'a list ==> bool"where "is_prefix [] _ = True" | "is_prefix (x#xs) [] = False" | "is_prefix (x#xs) (y#ys) = (x = y ∧ is_prefix xs ys)"
lemma is_prefix_prefix : "is_prefix xs ys = (∃ xs' . ys = xs@xs')" proof (induction xs arbitrary: ys) case Nil thenshow ?caseby auto next case (Cons x xs) show ?caseproof (cases "is_prefix (x#xs) ys") 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 ?thesis using Cons.IH by auto qed qed
fun add_prefixes :: "'a list list ==> 'a list list"where "add_prefixes xs = concat (map prefixes xs)"
lemma add_prefixes_set : "set (add_prefixes xs) = {xs' . ∃ xs'' . xs'@xs'' ∈ set xs}" proof - have"set (add_prefixes xs) = {xs' . ∃ x ∈ set xs . xs' ∈ set (prefixes x)}" unfolding add_prefixes.simps by auto alsohave"… = {xs' . ∃ xs'' . xs'@xs'' ∈ set xs}" proof (induction xs) case Nil thenshow ?caseusing prefixes_set by auto next case (Cons a xs) thenshow ?case proof - have"∧ xs' . xs' ∈ {xs'. ∃x∈set (a # xs). xs' ∈ set (prefixes x)} ⟷ xs' ∈ {xs'. ∃xs''. xs' @ xs'' ∈ set (a # xs)}" proof - fix xs' show"xs' ∈ {xs'. ∃x∈set (a # xs). xs' ∈ set (prefixes x)} ⟷ xs' ∈ {xs'. ∃xs''. xs' @ xs'' ∈ set (a # xs)}" unfolding prefixes_set by force qed thenshow ?thesis by blast qed qed finallyshow ?thesis by blast qed
lemma prefixes_set_ob : assumes"xs ∈ set (prefixes xss)" obtains xs' where"xss = xs@xs'" using assms unfolding prefixes_set by auto
lemma prefixes_finite : "finite { x ∈ set (prefixes xs) . P x}" by (metis Collect_mem_eq List.finite_set finite_Collect_conjI)
lemma prefixes_set_Cons_insert: "set (prefixes (w' @ [xy])) = Set.insert (w'@[xy]) (set (prefixes (w')))" unfolding prefixes_set proof (induction w' arbitrary: xy rule: rev_induct) case Nil thenshow ?case by (auto; simp add: append_eq_Cons_conv) next case (snoc x xs) thenshow ?case by (auto; metis (no_types, opaque_lifting) butlast.simps(2) butlast_append butlast_snoc) qed
lemma prefixes_set_subset: "set (prefixes xs) ⊆ set (prefixes (xs@ys))" unfolding prefixes_set by auto
lemma prefixes_prefix_subset : assumes"xs ∈ set (prefixes ys)" shows"set (prefixes xs) ⊆ set (prefixes ys)" using assms unfolding prefixes_set by auto
lemma prefixes_butlast_is_prefix : "butlast xs ∈ set (prefixes xs)" unfolding prefixes_set by (metis (mono_tags, lifting) append_butlast_last_id butlast.simps(1) mem_Collect_eq self_append_conv2)
lemma prefixes_take_iff : "xs ∈ set (prefixes ys) ⟷ take (length xs) ys = xs" proof show"xs ∈ set (prefixes ys) ==> take (length xs) ys = xs" unfolding prefixes_set by (simp add: append_eq_conv_conj)
show"take (length xs) ys = xs ==> xs ∈ set (prefixes ys)" unfolding prefixes_set by (metis (mono_tags, lifting) append_take_drop_id mem_Collect_eq) qed
lemma prefixes_Cons : assumes"(x#xs) ∈ set (prefixes (y#ys))" shows"x = y"and"xs ∈ set (prefixes ys)" proof - show"x = y" by (metis Cons_eq_appendI assms nth_Cons_0 prefixes_set_ob)
show"xs ∈ set (prefixes ys)" proof - obtain xs' xs'' where"(x#xs) = xs'"and"(y#ys) = xs'@xs''" by (meson assms prefixes_set_ob) thenhave"xs' = x#tl xs'" by auto thenhave"xs = tl xs'" using‹(x#xs) = xs'›by auto moreoverhave"ys = (tl xs')@xs''" using‹(y#ys) = xs'@xs''›‹xs' = x#tl xs'› by (metis append_Cons list.inject) ultimatelyshow ?thesis unfolding prefixes_set by blast qed qed
lemma prefixes_prepend : assumes"xs' ∈ set (prefixes xs)" shows"ys@xs' ∈ set (prefixes (ys@xs))" proof - obtain xs'' where"xs = xs'@xs''" using assms using prefixes_set_ob by auto thenhave"(ys@xs) = (ys@xs')@xs''" by auto thenshow ?thesis unfolding prefixes_set by auto qed
lemma prefixes_prefix_suffix_ob : assumes"a ∈ set (prefixes (b@c))" and"a ∉ set (prefixes b)" obtains c' c'' where"c = c'@c''" and"a = b@c'" and"c' ≠ []" proof - have"∃ c' c'' . c = c'@c'' ∧ a = b@c' ∧ c' ≠ []" using assms proof (induction b arbitrary: a) case Nil thenshow ?case unfolding prefixes_set by fastforce next case (Cons x xs) show ?caseproof (cases a) case Nil thenshow ?thesis by (metis Cons.prems(2) list.size(3) prefixes_take_iff take_eq_Nil) next case (Cons a' as) thenhave"a' # as ∈ set (prefixes (x #(xs@c)))" using Cons.prems(1) by auto
have"a' = x"and"as ∈ set (prefixes (xs@c))" using prefixes_Cons[OF ‹a' # as ∈ set (prefixes (x #(xs@c)))›] by auto moreoverhave"as ∉ set (prefixes xs)" using‹a ∉ set (prefixes (x # xs))›unfolding Cons ‹a' = x› prefixes_set by auto
ultimatelyobtain c' c'' where"c = c'@c''" and"as = xs@c'" and"c' ≠ []" using Cons.IH by blast thenhave"c = c'@c''"and"a = (x#xs)@c'"and"c' ≠ []" unfolding Cons ‹a' = x›by auto thenshow ?thesis using that by blast qed qed thenshow ?thesis using that by blast qed
lemma non_sym_dist_pairs'_elems_distinct: assumes"distinct xs" and"(x,y) ∈ set (non_sym_dist_pairs' xs)" shows"x ∈ set xs" and"y ∈ set xs" and"x ≠ y" proof - show"x ∈ set xs"and"y ∈ set xs" using non_sym_dist_pairs_subset assms(2) by (induction xs; auto)+ show"x ≠ y" using assms by (induction xs; auto) qed
lemma non_sym_dist_pairs_elems_distinct: assumes"(x,y) ∈ set (non_sym_dist_pairs xs)" shows"x ∈ set xs" and"y ∈ set xs" and"x ≠ y" using non_sym_dist_pairs'_elems_distinct assms unfolding non_sym_dist_pairs.simps by fastforce+
lemma non_sym_dist_pairs_elems : assumes"x ∈ set xs" and"y ∈ set xs" and"x ≠ y" shows"(x,y) ∈ set (non_sym_dist_pairs xs) ∨ (y,x) ∈ set (non_sym_dist_pairs xs)" using assms by (induction xs; auto)
lemma non_sym_dist_pairs'_elems_non_refl : assumes"distinct xs" and"(x,y) ∈ set (non_sym_dist_pairs' xs)" shows"(y,x) ∉ set (non_sym_dist_pairs' xs)" using assms proof (induction xs arbitrary: x y) case Nil thenshow ?caseby auto next case (Cons z zs) thenhave"distinct zs"by auto
have"x ≠ y" using non_sym_dist_pairs'_elems_distinct[OF Cons.prems] by simp
consider (a) "(x,y) ∈ set (map (Pair z) zs)" |
(b) "(x,y) ∈ set (non_sym_dist_pairs' zs)" using‹(x,y) ∈ set (non_sym_dist_pairs' (z#zs))›unfolding non_sym_dist_pairs'.simps by auto thenshow ?caseproof cases case a thenhave"x = z"by auto thenhave"(y,x) ∉ set (map (Pair z) zs)" using‹x ≠ y›by auto moreoverhave"x ∉ set zs" using‹x = z›‹distinct (z#zs)›by auto ultimatelyshow ?thesis using‹distinct zs› non_sym_dist_pairs'_elems_distinct(2) by fastforce next case b thenhave"x ≠ z"and"y ≠ z" using Cons.prems unfolding non_sym_dist_pairs'.simps by (meson distinct.simps(2) non_sym_dist_pairs'_elems_distinct(1,2))+
thenshow ?thesis using Cons.IH[OF ‹distinct zs› b] by auto qed qed
lemma non_sym_dist_pairs_elems_non_refl : assumes"(x,y) ∈ set (non_sym_dist_pairs xs)" shows"(y,x) ∉ set (non_sym_dist_pairs xs)" using assms by (simp add: non_sym_dist_pairs'_elems_non_refl)
lemma non_sym_dist_pairs_set_iff : "(x,y) ∈ set (non_sym_dist_pairs xs) ⟷ (x ≠ y ∧ x ∈ set xs ∧ y ∈ set xs ∧ (y,x) ∉ set (non_sym_dist_pairs xs))" using non_sym_dist_pairs_elems_non_refl[of x y xs]
non_sym_dist_pairs_elems[of x xs y]
non_sym_dist_pairs_elems_distinct[of x y xs] by blast
subsection‹Finite Linear Order From List Positions›
fun linear_order_from_list_position' :: "'a list ==> ('a × 'a) list"where "linear_order_from_list_position' [] = []" | "linear_order_from_list_position' (x#xs) = (x,x) # (map (λ y . (x,y)) xs) @ (linear_order_from_list_position' xs)"
fun linear_order_from_list_position :: "'a list ==> ('a × 'a) list"where "linear_order_from_list_position xs = linear_order_from_list_position' (remdups xs)"
lemma linear_order_from_list_position_set : "set (linear_order_from_list_position xs) = (set (map (λ x . (x,x)) xs)) ∪ set (non_sym_dist_pairs xs)" by (induction xs; auto)
lemma linear_order_from_list_position_total: "total_on (set xs) (set (linear_order_from_list_position xs))" unfolding linear_order_from_list_position_set using non_sym_dist_pairs_elems[of _ xs] by (meson UnI2 total_onI)
lemma linear_order_from_list_position_refl: "refl_on (set xs) (set (linear_order_from_list_position xs))" proof (rule refl_onI) show"∧x. x ∈ set xs ==> (x, x) ∈ set (linear_order_from_list_position xs)" unfolding linear_order_from_list_position_set using non_sym_dist_pairs_subset[of xs] by auto qed
lemma linear_order_from_list_position_antisym: "antisym (set (linear_order_from_list_position xs))" proof fix x y assume"(x, y) ∈ set (linear_order_from_list_position xs)" and"(y, x) ∈ set (linear_order_from_list_position xs)" thenhave"(x, y) ∈ set (map (λx. (x, x)) xs) ∪ set (non_sym_dist_pairs xs)" and"(y, x) ∈ set (map (λx. (x, x)) xs) ∪ set (non_sym_dist_pairs xs)" unfolding linear_order_from_list_position_set by blast+ then consider (a) "(x, y) ∈ set (map (λx. (x, x)) xs)" |
(b) "(x, y) ∈ set (non_sym_dist_pairs xs)" by blast thenshow"x = y" proof cases case a thenshow ?thesis by auto next case b thenhave"x ≠ y"and"(y,x) ∉ set (non_sym_dist_pairs xs)" using non_sym_dist_pairs_set_iff[of x y xs] by simp+ thenhave"(y, x) ∉ set (map (λx. (x, x)) xs) ∪ set (non_sym_dist_pairs xs)" by auto thenshow ?thesis using‹(y, x) ∈ set (map (λx. (x, x)) xs) ∪ set (non_sym_dist_pairs xs)›by blast qed qed
lemma non_sym_dist_pairs'_indices : "distinct xs ==> (x,y) ∈ set (non_sym_dist_pairs' xs) ==> (∃ i j . xs ! i = x ∧ xs ! j = y ∧ i < j ∧ i < length xs ∧ j < length xs)" proof (induction xs) case Nil thenshow ?caseby auto next case (Cons a xs) show ?caseproof (cases "a = x") case True thenhave"(a#xs) ! 0 = x"and"0 < length (a#xs)" by auto
have"y ∈ set xs" using non_sym_dist_pairs'_elems_distinct(2,3)[OF Cons.prems(1,2)] True by auto thenobtain j where"xs ! j = y"and"j < length xs" by (meson in_set_conv_nth) thenhave"(a#xs) ! (Suc j) = y"and"Suc j < length (a#xs)" by auto
thenshow ?thesis using‹(a#xs) ! 0 = x›‹0 < length (a#xs)›by blast next case False thenhave"(x,y) ∈ set (non_sym_dist_pairs' xs)" using Cons.prems(2) by auto thenshow ?thesis using Cons.IH Cons.prems(1) by (metis Suc_mono distinct.simps(2) length_Cons nth_Cons_Suc) qed qed
lemma non_sym_dist_pairs'_trans: "distinct xs ==> trans (set (non_sym_dist_pairs' xs))" proof fix x y z assume"distinct xs" and"(x, y) ∈ set (non_sym_dist_pairs' xs)" and"(y, z) ∈ set (non_sym_dist_pairs' xs)"
obtain nx ny where"xs ! nx = x"and"xs ! ny = y"and"nx < ny" and"nx < length xs"and"ny < length xs" using non_sym_dist_pairs'_indices[OF ‹distinct xs›‹(x, y) ∈ set (non_sym_dist_pairs' xs)›] by blast
have"¬(z, x) ∈ set (non_sym_dist_pairs' xs)" proof assume"(z, x) ∈ set (non_sym_dist_pairs' xs)" thenobtain nz' nx' where"xs ! nx' = x"and"xs ! nz' = z"and"nz'< nx'" and"nx' < length xs"and"nz' < length xs" using non_sym_dist_pairs'_indices[OF ‹distinct xs›, of z x] by metis
have"nx' = nx" using‹distinct xs›‹xs ! nx = x›‹xs ! nx' = x›‹nx < length xs›‹nx' < length xs›
nth_eq_iff_index_eq by metis moreoverhave"nz' = nz" using‹distinct xs›‹xs ! nz = z›‹xs ! nz' = z›‹nz < length xs›‹nz' < length xs›
nth_eq_iff_index_eq by metis ultimatelyhave"nz < nx" using‹nz'< nx'›by auto thenshow"False" using‹nx < nz›by simp qed thenshow"(x, z) ∈ set (non_sym_dist_pairs' xs)" using non_sym_dist_pairs'_elems_distinct(1)[OF ‹distinct xs›‹(x, y) ∈ set (non_sym_dist_pairs' xs)›]
non_sym_dist_pairs'_elems_distinct(2)[OF ‹distinct xs›‹(y, z) ∈ set (non_sym_dist_pairs' xs)›] ‹x ≠ z›
non_sym_dist_pairs_elems[of x xs z] unfolding non_sym_dist_pairs.simps ‹remdups xs = xs› by blast qed
lemma non_sym_dist_pairs_trans: "trans (set (non_sym_dist_pairs xs))" using non_sym_dist_pairs'_trans[of "remdups xs", OF distinct_remdups] unfolding non_sym_dist_pairs.simps by assumption
lemma linear_order_from_list_position_trans: "trans (set (linear_order_from_list_position xs))" proof fix x y z assume"(x, y) ∈ set (linear_order_from_list_position xs)" and"(y, z) ∈ set (linear_order_from_list_position xs)" then consider (a) "(x, y) ∈ set (map (λx. (x, x)) xs) ∧ (y, z) ∈ set (map (λx. (x, x)) xs)" |
(b) "(x, y) ∈ set (map (λx. (x, x)) xs) ∧ (y, z) ∈ set (non_sym_dist_pairs xs)" |
(c) "(x, y) ∈ set (non_sym_dist_pairs xs) ∧ (y, z) ∈ set (map (λx. (x, x)) xs)" |
(d) "(x, y) ∈ set (non_sym_dist_pairs xs) ∧ (y, z) ∈ set (non_sym_dist_pairs xs)" unfolding linear_order_from_list_position_set by blast+ thenshow"(x, z) ∈ set (linear_order_from_list_position xs)" proof cases case a thenshow ?thesis unfolding linear_order_from_list_position_set by auto next case b thenshow ?thesis unfolding linear_order_from_list_position_set by auto next case c thenshow ?thesis unfolding linear_order_from_list_position_set by auto next case d thenshow ?thesis unfolding linear_order_from_list_position_set using non_sym_dist_pairs_trans by (metis UnI2 transE) qed qed
subsection‹Find And Remove in a Single Pass›
fun find_remove' :: "('a ==> bool) ==> 'a list ==> 'a list ==> ('a × 'a list) option"where "find_remove' P [] _ = None" | "find_remove' P (x#xs) prev = (if P x then Some (x,prev@xs) else find_remove' P xs (prev@[x]))"
fun find_remove :: "('a ==> bool) ==> 'a list ==> ('a × 'a list) option"where "find_remove P xs = find_remove' P xs []"
lemma find_remove'_set : assumes"find_remove' P xs prev = Some (x,xs')" shows"P x" and"x ∈ set xs" and"xs' = prev@(remove1 x xs)" proof - have"P x ∧ x ∈ set xs ∧ xs' = prev@(remove1 x xs)" using assms proof (induction xs arbitrary: prev xs') case Nil thenshow ?caseby auto next case (Cons x xs) show ?caseproof (cases "P x") case True thenshow ?thesis using Cons by auto next case False thenshow ?thesis using Cons by fastforce qed qed thenshow"P x" and"x ∈ set xs" and"xs' = prev@(remove1 x xs)" by blast+ qed
lemma find_remove'_set_rev : assumes"x ∈ set xs" and"P x" shows"find_remove' P xs prev ≠ None" using assms(1) proof(induction xs arbitrary: prev) case Nil thenshow ?caseby auto next case (Cons x' xs) show ?caseproof (cases "P x") case True thenshow ?thesis using Cons by auto next case False thenshow ?thesis using Cons using assms(2) by auto qed qed
lemma find_remove_None_iff : "find_remove P xs = None ⟷¬ (∃x . x ∈ set xs ∧ P x)" unfolding find_remove.simps using find_remove'_set(1,2)
find_remove'_set_rev by (metis old.prod.exhaust option.exhaust)
lemma find_remove_set : assumes"find_remove P xs = Some (x,xs')" shows"P x" and"x ∈ set xs" and"xs' = (remove1 x xs)" using assms find_remove'_set[of P xs "[]" x xs'] by auto
fun find_remove_2' :: "('a==>'b==>bool) ==> 'a list ==> 'b list ==> 'a list ==> ('a× 'b × 'a list) option" where "find_remove_2' P [] _ _ = None" | "find_remove_2' P (x#xs) ys prev = (case find (λy . P x y) ys of Some y ==> Some (x,y,prev@xs) | None ==> find_remove_2' P xs ys (prev@[x]))"
fun find_remove_2 :: "('a ==> 'b ==> bool) ==> 'a list ==> 'b list ==> ('a × 'b × 'a list) option"where "find_remove_2 P xs ys = find_remove_2' P xs ys []"
lemma find_remove_2'_set : assumes"find_remove_2' P xs ys prev = Some (x,y,xs')" shows"P x y" and"x ∈ set xs" and"y ∈ set ys" and"distinct (prev@xs) ==> set xs' = (set prev ∪ set xs) - {x}" and"distinct (prev@xs) ==> distinct xs'" and"xs' = prev@(remove1 x xs)" and"find (P x) ys = Some y" proof - have"P x y ∧ x ∈ set xs ∧ y ∈ set ys ∧ (distinct (prev@xs) ⟶ set xs' = (set prev ∪ set xs) - {x}) ∧ (distinct (prev@xs) ⟶ distinct xs') ∧ (xs' = prev@(remove1 x xs)) ∧ find (P x) ys = Some y" using assms proof (induction xs arbitrary: prev xs' x y) case Nil thenshow ?caseby auto next case (Cons x' xs) thenshow ?caseproof (cases "find (λy . P x' y) ys") case None thenhave"find_remove_2' P (x' # xs) ys prev = find_remove_2' P xs ys (prev@[x'])" using Cons.prems(1) by auto hence *: "find_remove_2' P xs ys (prev@[x']) = Some (x, y, xs')" using Cons.prems(1) by simp
have"x' ≠ x" by (metis "*" Cons.IH None find_from) moreoverhave"distinct (prev @ x' # xs) ⟶ distinct ((x' # prev) @ xs)" by auto ultimatelyshow ?thesis using Cons.IH[OF *] by auto next case (Some y') thenhave"find_remove_2' P (x' # xs) ys prev = Some (x',y',prev@xs)" by auto thenshow ?thesis using Some using Cons.prems(1) find_condition find_set by fastforce qed qed thenshow"P x y" and"x ∈ set xs" and"y ∈ set ys" and"distinct (prev @ xs) ==> set xs' = (set prev ∪ set xs) - {x}" and"distinct (prev@xs) ==> distinct xs'" and"xs' = prev@(remove1 x xs)" and"find (P x) ys = Some y" by blast+ qed
lemma find_remove_2'_strengthening : assumes"find_remove_2' P xs ys prev = Some (x,y,xs')" and"P' x y" and"∧ x' y' . P' x' y' ==> P x' y'" shows"find_remove_2' P' xs ys prev = Some (x,y,xs')" using assms proof (induction xs arbitrary: prev) case Nil thenshow ?caseby auto next case (Cons x' xs) thenshow ?caseproof (cases "find (λy . P x' y) ys") case None thenshow ?thesis using Cons by (metis (mono_tags, lifting) find_None_iff find_remove_2'.simps(2) option.simps(4)) next case (Some a) thenhave"x' = x"and"a = y" using Cons.prems(1) unfolding find_remove_2'.simps by auto thenhave"find (λy . P x y) ys = Some y" using find_remove_2'_set[OF Cons.prems(1)] by auto thenhave"find (λy . P' x y) ys = Some y" using Cons.prems(3) proof (induction ys) case Nil thenshow ?caseby auto next case (Cons y' ys) thenshow ?case by (metis assms(2) find.simps(2) option.inject) qed
thenshow ?thesis using find_remove_2'_set(6)[OF Cons.prems(1)] unfolding‹x' = x› find_remove_2'.simps by auto qed qed
lemma find_remove_2_strengthening : assumes"find_remove_2 P xs ys = Some (x,y,xs')" and"P' x y" and"∧ x' y' . P' x' y' ==> P x' y'" shows"find_remove_2 P' xs ys = Some (x,y,xs')" using assms find_remove_2'_strengthening by (metis find_remove_2.simps)
lemma find_remove_2'_prev_independence : assumes"find_remove_2' P xs ys prev = Some (x,y,xs')" shows"∃ xs'' . find_remove_2' P xs ys prev' = Some (x,y,xs'')" using assms proof (induction xs arbitrary: prev prev' xs') case Nil thenshow ?caseby auto next case (Cons x' xs) show ?caseproof (cases "find (λy . P x' y) ys") case None thenshow ?thesis using Cons.IH Cons.prems by auto
next case (Some a) thenshow ?thesis using Cons.prems unfolding find_remove_2'.simps by simp qed qed
lemma find_remove_2'_filter : assumes"find_remove_2' P (filter P' xs) ys prev = Some (x,y,xs')" and"∧ x y . ¬ P' x ==>¬ P x y" shows"∃ xs'' . find_remove_2' P xs ys prev = Some (x,y,xs'')" using assms(1) proof (induction xs arbitrary: prev prev xs') case Nil thenshow ?caseby auto next case (Cons x' xs) thenshow ?caseproof (cases "P' x'") case True thenhave *:"find_remove_2' P (filter P' (x' # xs)) ys prev = find_remove_2' P (x' # filter P' xs) ys prev" by auto
show ?thesis proof (cases "find (λy . P x' y) ys") case None thenshow ?thesis by (metis Cons.IH Cons.prems find_remove_2'.simps(2) option.simps(4) *) next case (Some a) thenhave"x' = x"and"a = y" using Cons.prems unfolding * find_remove_2'.simps by auto
show ?thesis using Some unfolding‹x' = x›‹a = y› find_remove_2'.simps by simp qed next case False thenhave"find_remove_2' P (filter P' xs) ys prev = Some (x,y,xs')" using Cons.prems by auto
from False assms(2) have"find (λy . P x' y) ys = None" by (simp add: find_None_iff) thenhave"find_remove_2' P (x'#xs) ys prev = find_remove_2' P xs ys (prev@[x'])" by auto
show ?thesis using Cons.IH[OF ‹find_remove_2' P (filter P' xs) ys prev = Some (x,y,xs')›] unfolding‹find_remove_2' P (x'#xs) ys prev = find_remove_2' P xs ys (prev@[x'])› using find_remove_2'_prev_independence by metis qed qed
lemma find_remove_2_filter : assumes"find_remove_2 P (filter P' xs) ys = Some (x,y,xs')" and"∧ x y . ¬ P' x ==>¬ P x y" shows"∃ xs'' . find_remove_2 P xs ys = Some (x,y,xs'')" using assms by (simp add: find_remove_2'_filter)
lemma find_remove_2'_index : assumes"find_remove_2' P xs ys prev = Some (x,y,xs')" obtains i i' where"i < length xs" "xs ! i = x" "∧ j . j < i ==> find (λy . P (xs ! j) y) ys = None" "i' < length ys" "ys ! i' = y" "∧ j . j < i' ==>¬ P (xs ! i) (ys ! j)" proof - have"∃ i i' . i < length xs ∧ xs ! i = x ∧ (∀ j < i . find (λy . P (xs ! j) y) ys = None) ∧ i' < length ys ∧ ys ! i' = y ∧ (∀ j < i' . ¬ P (xs ! i) (ys ! j))" using assms proof (induction xs arbitrary: prev xs' x y) case Nil thenshow ?caseby auto next case (Cons x' xs) thenshow ?caseproof (cases "find (λy . P x' y) ys") case None thenhave"find_remove_2' P (x' # xs) ys prev = find_remove_2' P xs ys (prev@[x'])" using Cons.prems(1) by auto hence *: "find_remove_2' P xs ys (prev@[x']) = Some (x, y, xs')" using Cons.prems(1) by simp
have"x' ≠ x" using find_remove_2'_set(1,3)[OF *] None unfolding find_None_iff by blast
obtain i i' where"i < length xs"and"xs ! i = x" and"(∀ j < i . find (λy . P (xs ! j) y) ys = None)"and"i' < length ys" and"ys ! i' = y"and"(∀ j < i' . ¬ P (xs ! i) (ys ! j))" using Cons.IH[OF *] by blast
have"Suc i < length (x'#xs)" using‹i < length xs›by auto moreoverhave"(x'#xs) ! Suc i = x" using‹xs ! i = x›by auto moreoverhave"(∀ j < Suc i . find (λy . P ((x'#xs) ! j) y) ys = None)" proof - have"∧ j . j > 0 ==> j < Suc i ==> find (λy . P ((x'#xs) ! j) y) ys = None" using‹(∀ j < i . find (λy . P (xs ! j) y) ys = None)›by auto thenshow ?thesis using None by (metis neq0_conv nth_Cons_0) qed moreoverhave"(∀ j < i' . ¬ P ((x'#xs) ! Suc i) (ys ! j))" using‹(∀ j < i' . ¬ P (xs ! i) (ys ! j))› by simp
ultimatelyshow ?thesis using that ‹i' < length ys›‹ys ! i' = y›by blast next case (Some y') thenhave"x' = x"and"y' = y" using Cons.prems by force+
have"0 < length (x'#xs) ∧ (x'#xs) ! 0 = x' ∧ (∀ j < 0 . find (λy . P ((x'#xs) ! j) y) ys = None)" by auto moreoverobtain i' where"i' < length ys"and"ys ! i' = y'" and"(∀ j < i' . ¬ P ((x'#xs) ! 0) (ys ! j))" using find_sort_index[OF Some] by auto ultimatelyshow ?thesis unfolding‹x' = x›‹y' = y›by blast qed qed thenshow ?thesis using that by blast qed
lemma find_remove_2_index : assumes"find_remove_2 P xs ys = Some (x,y,xs')" obtains i i' where"i < length xs" "xs ! i = x" "∧ j . j < i ==> find (λy . P (xs ! j) y) ys = None" "i' < length ys" "ys ! i' = y" "∧ j . j < i' ==>¬ P (xs ! i) (ys ! j)" using assms find_remove_2'_index[of P xs ys "[]" x y xs'] by auto
lemma find_remove_2'_set_rev : assumes"x ∈ set xs" and"y ∈ set ys" and"P x y" shows"find_remove_2' P xs ys prev ≠ None" using assms(1) proof(induction xs arbitrary: prev) case Nil thenshow ?caseby auto next case (Cons x' xs) thenshow ?caseproof (cases "find (λy . P x' y) ys") case None thenhave"x ≠ x'" using assms(2,3) by (metis find_None_iff) thenhave"x ∈ set xs" using Cons.prems by auto thenshow ?thesis using Cons.IH unfolding find_remove_2'.simps None by auto next case (Some a) thenshow ?thesis by auto qed qed
lemma find_remove_2'_diff_prev_None : "(find_remove_2' P xs ys prev = None ==> find_remove_2' P xs ys prev' = None)" proof (induction xs arbitrary: prev prev') case Nil thenshow ?caseby auto next case (Cons x xs) show ?caseproof (cases "find (λy . P x y) ys") case None thenhave"find_remove_2' P (x#xs) ys prev = find_remove_2' P xs ys (prev@[x])" and"find_remove_2' P (x#xs) ys prev' = find_remove_2' P xs ys (prev'@[x])" by auto thenshow ?thesis using Cons by auto next case (Some a) thenshow ?thesis using Cons by auto qed qed
lemma find_remove_2'_diff_prev_Some : "(find_remove_2' P xs ys prev = Some (x,y,xs') ==>∃ xs'' . find_remove_2' P xs ys prev' = Some (x,y,xs''))" proof (induction xs arbitrary: prev prev') case Nil thenshow ?caseby auto next case (Cons x xs) show ?caseproof (cases "find (λy . P x y) ys") case None thenhave"find_remove_2' P (x#xs) ys prev = find_remove_2' P xs ys (prev@[x])" and"find_remove_2' P (x#xs) ys prev' = find_remove_2' P xs ys (prev'@[x])" by auto thenshow ?thesis using Cons by auto next case (Some a) thenshow ?thesis using Cons by auto qed qed
lemma find_remove_2_None_iff : "find_remove_2 P xs ys = None ⟷¬ (∃x y . x ∈ set xs ∧ y ∈ set ys ∧ P x y)" unfolding find_remove_2.simps using find_remove_2'_set(1-3) find_remove_2'_set_rev by (metis old.prod.exhaust option.exhaust)
lemma find_remove_2_set : assumes"find_remove_2 P xs ys = Some (x,y,xs')" shows"P x y" and"x ∈ set xs" and"y ∈ set ys" and"distinct xs ==> set xs' = (set xs) - {x}" and"distinct xs ==> distinct xs'" and"xs' = (remove1 x xs)" using assms find_remove_2'_set[of P xs ys "[]" x y xs'] unfolding find_remove_2.simps by auto
lemma find_remove_2_removeAll : assumes"find_remove_2 P xs ys = Some (x,y,xs')" and"distinct xs" shows"xs' = removeAll x xs" using find_remove_2_set(6)[OF assms(1)] by (simp add: assms(2) distinct_remove1_removeAll)
lemma find_remove_2_length : assumes"find_remove_2 P xs ys = Some (x,y,xs')" shows"length xs' = length xs - 1" using find_remove_2_set(2,6)[OF assms] by (simp add: length_remove1)
fun separate_by :: "('a ==> bool) ==> 'a list ==> ('a list × 'a list)"where "separate_by P xs = (filter P xs, filter (λ x . ¬ P x) xs)"
lemmaext "separate_by P xs = foldr (λeil([],])" proof case thenshow ?case x,) <set next cme casexs
letby ura yuto
haveforce using Cons.IH by auto moreoverhave"separate_by P (a#xs) = ?f a (filter P xs, filter (λ moreoverv"=and (bs @ [b]) ! i} = {?m}" ultimately show ?case by esP a" ) qed
fun find_remove_2_all "find_remove_2_all P xs ys = (map (λ ,filter (λ
fun find_remove_2_all' :: "(>'b ==> 'b list (('a ×
by in (map (<dots
emma by proof - let ?s1 = "map ed let ?f1 = "filter (λd (<>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
let ? let ?f2 = java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "macro" is null
have "find_remove_2_all P xs ys = (?s1 snd
imp moreoverhave find_remove_2_all proof snd (cs ! 0) < ne have= "s snd (cs ! i) ≠ set (snd ((xys # xyss) ! i))))) by force then show ?thesis unfolding find_remove_2_all'.simps Let_def separ k<length xs) ∧ (f (xs ! k)) ∧ (∀ . ¬ (f (xs ! j)))" moreoverhave then"casefid_idx f s o Some \ightarrow (Suc k) | None ==> moreover have "?s1 = ?s2" by
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 by (induction xs; auto) ultimately show ?thesis by simp qed
subsection ‹
fun pow_list :: " a list \>'a list list" where
"pow_list [] = [[]]" |
"pow_list (x#xs) = (let pxs = pow_list xs in pxs @ map (λ
"sps(ow__lit xs)= Powo(stx)"
java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
Nil
then show ?case by aue" |
case (Cons x xs)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 87 out of bounds for length 29
moreover ex \ (image (insert x) (set (map set (pow_list xs))))"
proof -o
have "∧ ==>
proof -
fix ys assume "ys ∈
then consider (a) "ys ∈ set (map set (pow_list xs))" |
ys<>
unfolding pow_list.simps Let_def by auto
then show "ys ∈ set (map set (pow_list xs)) ∪
by (cases; auto)
moreover have "∧ ∪(fixs) ==>le ? "ae(leg sz"
fix ys assume "ys ∈ase
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
thenc
(image (insert x) (set (map set (pow_list xs))))"
then show "ys ∈ set (map set (pow_list (x#xs)))"
unfolding pow_list.simps Let_def by (cases; auto)
qed
ltimatelysow?thesis byblast
ultimately show ?case
(ca es"(@ [x]]"; autto)
Removing Subsets in a List of Sets›
lemma remove1_length : "x ∈ set xs ==>by auto by (induction xs; auto)
function remove_subsets :: "'a set list ==> "remove_subsets [] = []" |
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "brackoff" is null Somet ?hsis None ==> by pat_completeness auto termination
java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 7 have "java.lang.NullPointerException by (metis list.set (list_ordered_pairsxs (y,x) ∈ moreoverhave"(∧ f - fix x :: "'a set" fix xs y'xs' y' xs' assume "find_removeprefixes_Cons thenhave"ed by auto
have "length xs' = length xs - 1" using find_remove_set(23[O\ by (simp add: length_remove1) then have "length (y'#xs') = length xs" using find_remove_set(2)[OF ‹find_remove ((⊂) x) xs = Some (y',xs')›] using remove1_length by fastforce have "length (filter (<lambdacase
thenhave"length'# filer (\lambday ¬ y ⊆ imp then have "length (y' # filter (λx = z›‹ unfolding\<opencase thenshow"(y'#filter(\<lambda>y.\<notultimatelyshowthesisis to qed ultimatelyshow?thesis by qed
lemmaremove_subsets_set:"set(remove_subsetsxss)={xs.xs\<in>setxss\<and>(\<nexists>xs'.xs'\<in>setxss\<java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 proofthen"y\in>set(map(\<lambda>x.(x,x))xs)\<union>set(non_sym_dist_pairsxs)" caseless show?caseproof(casesxss)
"inct<Longrightarrow>(xy\>ton_sym_dist_pairss) thenshow?thesisbyauto next case(Consxxss') show?thesisproof(cases"find_remove(\<lambda>y.x\<subset>y)xss'") caseNone thenhave"sing.Hssjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 usingfind_remove_None_iffbymetis
have"length(filter(\<lambda>y.not(y\<subseteq>x))xss')<lengthxss" usingCons by(mesondual_order.transimpossible_ConsleIlength_filter_le) have"remove_subsets(x#xss')=x#(remove_subsets(filter(\<lambda>y.\<not>(y\<subseteq>x))xss'))" usingNoneyuto thenhave"set(remove_subsets(x#xss'))=insertx{xs\<in>set(filter(\<lambda>y.\<not>proof usingless[OF\<penengther(lambda>y.\<not>(\subseteq))xss')<lengthxss\<close>] byauto have\dots>=xs.xs<innth_eq_iff_index_eqjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32 proof- have"\<And>xs.xs\<in>insertx{xs\<in>set(filter(\<lambda>y.\<not>y\<subseteq>x)xss'<nexistsxs'.xs'\set(filter(\<lambda>noty\<subseteq>x)xss')\<and>xs\<subset>xs'} \<Longrightarrow>xs\<in>{xs\yauto proof- \inset(filter(\<lambda>y.\<not>y\<subseteq>x)xss').\<nexists>xs'.xs'\<in>set(filter(\<lambda>y.\<not><subseteq>ss<nd>xs\<subset>xs'}" thenconsider"xs=x"|"xs\<in>set(filter(\<lambda>y.\<proof- next thenshow"xs\<in>{xs\<in>set(x#xss').\<nexists>xs'.qed )proofctionarbitraryrev qed moreoverhave"\<And>xs.xs\<in>{xs\<in>set(x#xss').\<nexists>xs'.xs'\<thenthesisons \<Longrightarrow>xs\<in>insertx{xs\<in>nd"x\insetxs" proof- fixxsassume"xs\<in>{xs\<in>set(x#xss').\<nexists>xs'.xs'\<in>set(x#xss')\<and>xs\<subset>xs'}" thenhave"xs\<in>set(x#xss')"and"\<nexists>xs'.xs'\<in>set(x#xss')\<and>xs\<subset>xs'" byblast+ thenconsider"xs=x"|"xs\<in>setxss'"byauto thenshow"xs\<in>insertx{xs\<in>set(filter(\<lambda>y.\<not>y\<subseteq>x)xss').\<nexists>xs'.xs'\usingConsprems)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 proofcases case1 thenshow?thesisbyauto next case2 show?thesisproof(cases"xs\<subseteq>x") thenshow?thesis using\<open>\<nexists>xs'.xs'\<in>set(x#xss')\<and>xs\<subset>xs'\<close>byauto caseFalse thenhave"xs\<in>set(filter(\<lambda>y.\<not>y\<subseteq using2byauto moreoverhave"\<nexists>xs'.xs'\<in>set(filter(\<lambda>y.\<usingConsjava.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38 ,\set(non_sym_dist_pairsxs" ultimatelyshow?thesisbyauto qed qed ultimatelyshow?thesis by(mesonsubset_antisymthenhave"anda qed allyyshow?thesisisnfoldingoldingldinginggConsssymmetricbyassumption next case(Somea) thenobtainy'xs'where*:"find_remove(\<lambda>y.x\<subset>y)xss'=Some(y',xs')"byforce
have"remove_subsets(x#xss')=remove_subsets(y'#(filter(\<lambda>y.\<not>(y\<subseteq>x))xs'auto using*byauto thenhave"set(remove_subsets(x#xss'))={xs\<in>set"xsjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 usingless[OF\<open>length(y'#filter(\<lambda>y.\<not>y\<subseteqfind_remove_2_: byauto alsohave"\<dots>={xs.xs\<in>set(x#xss')\<and>(\<nexists>xs'.xs'\<in>set(x#xss')thenx>x'" proof- have"\<And>xsto xs\<in>{xs\<in>set(x#'\xs'.xs'\<in>set(x#sss<and>xs\<subset>xs'}" proof- fixxsassume"xs\<in>{xs\<in>set(y'#filter(\<lambda>y.\<not>y\<subseteq thenhave"xs\<in>set(y'#filter(\<lambda>y.\<not>y\<subseteq(.haustnustjava.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44 byblast+
havejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 using\<open>xs\<in>set(y'#filter(\<lambda>y.\<not>y\<subseteq>x)xs')\<close>find_remove_set(2using_2[s byauto moreoverhave"\<nexists>xs'.s<>set>xs\<subset>xs'" using\<open>\<nexists>xs'a.xs'a\<in>set(y'#filter(\<lambda>y.\<not>y\<subseteq>x)xs')\<andjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 by(metisdual_order.strict_transfilter_list_setin_set_remove1list.set_intros(1)list.set_intros(2)psubsetIset_ConsD) ultimatelyshow"xs\in{s\<in>set(x#xss').\<nexists>xs'.xs'\<in>set(x#xss')\<and>xs\<subset>xs'}" byblast qed moreoverhave"\<And>xs.xs\<in>{xs\<in xs\<in>{xs\<in>set'ter<>y<oty\<subseteq>x)xs').\<nexists>xs'a.xs'a\<in>set(y'#filter(\<lambda>y.\<not>y\<subseteq>x)xs')\<and>xs\<subset>xs'a}" proof- fixxsassume"xs\byblast thenhave"xs\<in>set(x#xss')"and"\<nexists>xs'.xs'\<in>set(x#xss')a byblast+
thenhave"xs\<in>set(y'lter<>.\<not>y\<subseteq)xs usingfind_remove_set[OF*] by(metisfilter_list_setin_set_remove1list. overrave<exists>xs'a.xs'a\<in>set(y'#filter(\<lambda>ywisjava.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22 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'#casesxss byblast qed ultimatelyshow?thesisbyblast qed finallyshow?thesisunfoldingConsbyassumption qed qed qed
funless_sum::"'a+'b\<Rightarrow>java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9 "less_sumab=(a\<le>b\<and>a\<noteq>b)"
instanceo_classessses end
nstantiationm:((linorderinorder,linorder)linorder begin
lemmaless_le_not_le_sum fixesx::"'a+'b" andy::"'a+'b" shows"(x<y)=(x\<le>y\<and>\<not>yusing<>s\<in>set(y'#filter(\<lambda>y.\<not>y\<subseteq>x)xs')\<close>find_remove_set(2java.lang.StringIndexOutOfBoundsException: Index 127 out of bounds for length 127 by(casesx;casesy;auto) lemmaorder_refl_sum: fixesx::"'a+'b" shows"x\<le>x" by(casesx;auto)
have"\<And>zs.(\<nexists>ys.ys\<noteq>[]\<and>zs@ys\<in>(setxs))=(\<forall>ys\<in>setxs.is_prefixzsys\<longrightarrow>zs=ysbyjava.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16 unfoldingis_prefix_prefixbyauto thenshow?thesis unfolding*filter_setbyauto qed
have"<Andxycase(Sucjjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18 proof- fixxyassume"x\<in>xs"and"y\<in>xs"and"assign_indicesxsx=assign_indicesxsy"
obtainiwhere"find_index((=)x)(sorted_list_of_setxs)=Somei" usingfind_index_exhaustive[ofassumes<>et" using\<open>x\<by(metisSuc_leIssmsdrop_conv_nth__nv_nththlast_snocnoctake_hd_dropero_less_Sucthenhowthesisisfoldinglinear_order_from_list_position_set byblast thenhave"assign_indicesxsx=i"
java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 13
show"x=y" usingfind_index_index(2)[OF\<open>find_index((=)x)(sorted_list_of_setxs)=Somei\<close>] singng(F<openfind_index()sorted_list_of_set=Somei\close] byauto qed moreoverhave"(assign_indicesxs=<xs}" roof show"assign_indicesxs`xs\<subseteq>{..<cardxs}" proof fixiassume"i\ thenobtainxwhere"x\<in>xs"and"i=assign_indicesxsx" byblast moreoverobtainjwhere"find_index((=)x)(sorted_list_of_setxs)=Somej" usingfind_index_exhaustive[of"sorted_list_of_setxs"casejava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15 \>\<in>xs\<close>unfolding* byblast ultimatelyhave"find_index((=)x)(sorted_list_of_setxs)=Somei" byauto >{..<cardxs}" usingfind_index_index_ndexx)OFopenfind_index((=)x)(sorted_list_of_setxs)=Somei\<close>] byauto qed show"{..<cardxs}\<subseteq>assign_indicesxs`xs" proof fixiassume"i\<in>{..<cardxs}fromprems\foralli<lengthss-1.ss!i\<subset>ss!Suci" thenhave"i<ngthsorted_list_of_set byauto thenhave"sorted_list_of_setxs!ithenshow?java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40 using"*"nth_membyblast thenobtainjwhere"find_index((=)(sorted_list_of_setxs!i))(sorted_list_of_setxs)=Somej" unfolding* byblast have"i=j" usingfind_index_index(1,2)[OF\<open>find_index((=)(sorted_list_of_setxs!i))(sorted_list_of_setxs)=Somej<>] using\<open>i<length(sorted_list_of_setxs)\<close>distinct_sorted_list_of_setnth_eq_iff_index_eqst thenshow"i\<in>assign_indicesxs using\<open>find_index((=)(sorted_list_of_setxs!i))(sorted_list_of_setxs)=Somej\<close> by(metis\<open>"have"\not<i\orf(xs!ixs!Sucj) qed qed ultimatelyshow?thesis unfoldingbij_betw_definj_on_defbyblast qed
lemmafilter_length_weakening: assumes"\<And>q.f1q\<Longrightarrow>f2q" shows"length(filterf1p)\<le>length(filterf2p)" proof(inductionp) caseNil nhow?asebyuto next case(Consap) thenshow?caseusingassmsby(cases"f1a";auto) qed
lemmamax_length_elem: fixesultimatelyshow?hesisusingIHOF*java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49 mes"finitexs" and"xs\<noteq>{}" shows"\<exists>x\<in>xs.\<not>(\<exists>y\<in>xs.lengthy>lengthx)" usingassmsproof(inductionxs) caseempty thenshow?casebyauto next (xF thenshowcaseproofcases"F=}" caseTrue thenshow?thesisbyblast next False thenobtainywhere"y\<in>F"and"\<not>and"find(Px)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 usinginsert.IHbyblast thenshow?thesisusingdual_order.strict_transby(cases"lengthx>lengthy";auto) qed qed
lemmalength_elem fixesxs::"'alistset"
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
lemmalist_distinct_prefix: <>i.ilengthxs\<Longrightarrow>xs!i\<notin>set(takeixs)" shows"distinctxs" proof- have"\<And>j.distinct(takej proof- fixj show"distinct(takejxs)" proof(inductionj) 0 thenshow?casebyauto next case(Sucj) thenshow?caseproof(cases"Sucj\<le>lengthxs") caseTrue thenveSucjs(kexss by(simpadd:Suc_le_eqtake_Suc_conv_app_nth) thenshow?thesisusingSuc.IHassms[ofj]Truebyauto next caseFalse thenhave"take(Sucj)xs\<And>x'.x'\<ge>Sucx\<Longrightarrow>x'<(:prev'xs'java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60 thenshow?thesisusingSuc.IHbyauto qed qed java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 then?.premsunfoldingfind_remove_2 byblast thenshow?thesisbyauto qed
lemmarev_induct2[consumes1,case_namesNilsnoc]: '>pj and"P[][]" and"(\<And>xxsyys.find_remove_2P(ilter'xsSome(,,s)> shows"Pxsys" arbitrary caseNil showaseuto 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
lemmalist_prefix_subset:"\<exists>ys.ts=xs@ys\<Longrightarrow>setxs\<subseteq>setts"byauto lemmalist_map_set_prop:"x\<in>set(mapfxs)\<Longrightarrow>\<forall>y.P(fy)\<Longrightarrow>Px"byauto lemmalist_concat_non_elem:"x\<notin>setxs\<proof(inductionxsarbitrary:prevxsxy lemmalist_prefix_elem:"x\<in>set(xs@ys)\<Longrightarrow>x\<notin>setys\<Longrightarrow>x\<in>setxs"byauto lemmalist_map_source_elem:"x\thenshow?byautojava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
have"\<And>k.\<exists>ss.(lengthss=Suck)\<and>(hdss=S)\<and>(\<forall>i<k.ss!i\<subset>ss!(Suci))\<and>(setss\<subseteq>X)" proof- fixkshow"\<exists>ss.(lengthss=Suck)\<and>(hdss=S)\<and>(\<forall>i<k.ss!i\<subset>ss!(Suci))\<and>(setss\<subseteq>X)" proof(inductionk) case0 have"length[S]=Suc0\<and>hd[S]=S\<and>(\<forall>i<0.[S]!i\<subset>[S]!(Suci))\<and>(setthenshowhesisnginsertrtblast thenshow?casebyblast next case(Suck) thenobtainssere"lengths= and"hdss=S" and"(\<forall>i<k.ss!i\<subset>ss!Suci)" and"setss\<subseteq>X" byblast thenhave"ss!k\<in>Xjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32 byauto moreoverhave"S\<subseteq>(ss!k)" proof- have"\<And>i.i<Suck\<Longrightarrow>S\<subseteq>( proofjava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15 fixiassume"i<Suck" thenshow"S\<subseteq>(ss!i)" proof(inductioni) case0 thenshow?caseusing\<open>hdss=S\<close>\<open>lengthss=Suck\<close> by(metishd_conv_nthlist.size(3)nat.distinct(1)order_refl) next case(Suci) thenhave"S\<subseteq>ss!i"and"i<k"byauto thenhave"ss!i\<subset>ss!Suci"using\<open>(\<forall>i<k.ss!i\<subset>ss!Suci)\<close>byblast thenshow?caseusing\<open>S\<subseteq>ss!\<>byuto qed qed show?esisusing<open>lengthss=Suck<close>auto qed ultimatelyobtainT'where"T'\<in>X"and"ss!k\<subset>T'" using*bymeson
let?ss="ss@[T']"
havelength=Suc(Suckjava.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38 using\<open>lengthss=Suck\<close>byauto moreoverhave"hd?ss=S" using\<opendifferent_lists_shared_prefix moreoverhave"(\<forall>i<Suck.?ss!i\<subset>?ss!Suci)" using\<open>(\<forall>i<k.ss!i\<subset>ss!Suci)\<close>\<open>ss!k\<subset>T'\<close> by(metisSuc_lessI\<open>lengthss=Suck\<close>diff_Suc_1less_SucEnth_appendnth_append_length)thenshow?thesis moreoverhave"set?ss\<subseteq>X"next using\<open>setss\<subseteq>X\<close>\<open>T'\<in>X\<close>byauto ultimatelyshow?casebyblast qed qed
have**:"\<And>i(ss::'asetlist).(\<forall>i<by(inductionuto 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 casemoreoverhave"\Andy.y\in>s<Longrightarrowlengthy<Suc(Max(length`xs))" thenhave"\<forall>s\<in>set(takeiqed 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\<>ss!(Suci)"usingSuc.premsbyauto moreoverhave"(take(Suci)ss)=(takeiss)@[ss!i]"usingSuc.prems(1proof 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> proof(inductionsscase(snocxxs caseNil thenshow?casebyauto next case(snocass) oce"><ss-.\subsetijava.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80 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 howyto qed
thenhave"card(setss)=Suc(cardX)" using\<open>(lengthss=Suc(cardX))\<close>by(simpadd:distinct_card) thenhow"se using\<open>setss\<subseteq> 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
lemmalist_index_fun_gt:"\<And>xs(f::'a\<Rightarrow>nat)ij. (\<And>i.Suci<lengthxs\<Longrightarrow>f(xs!i)>f(xs!(Suci))) \<Longrightarrow>j<i \<Longrightarrow>i<lengthxs \<Longrightarrow>f(xs!j)let?filter\lambda\lambda>P)=Nonexsjava.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75 proof- fixxs::"'alist" fixf::"'a\<Rightarrow>nat" fixij assume"(\<And>i.Suci<lengthxs\<Longrightarrow>f(xs!i)>f(xs!(Suci)))" and"j<i" and"i<lengthxs" thenshow"f(xs!j)>f(xs!i)" proof(induction"i-j"arbitrary:ij) case0 thenshow?casebyauto next case(Sucx) thenshow?case proof- havef1:"\<forall>n.\<not>Sucn<lengthxs\<or>f(xs!Sucn)<f(xs!n)" usingSuc.prems(1)bypresburger havef2:"\<forall>nna.\<not>n<na\<or>Sucn\<le>na" usingSuc_leIbysatx have"x=i-Sucj" by(metisSuc.hyps(2)Suc.prems(2)Suc_diff_Sucnat.simps(1)) thenhave"\<not>Sucj<i\<or>f(xs!i)<f(xs!Sucj)" usingf1Suc.hyps(1)Suc.prems(3)byblast thenshow?thesis usingf2f1by(metisSuc.prems(2)Suc.prems(3)leIle_less_transnot_less_iff_gr_or_eq) qed qed qed
lemmafinite_set_elem_maximal_extension_ex: assumes"xs\<in>S" and"finiteS" shows"\<exists>ys.xs@ys\<in>S\<and>\<not>(\<exists>zs.zs\<noteq>[]\<and>xs@ys@zs\<in>S)" using\<open>finiteS\<close>\<open>xs\<in>S\<close>proof(inductionSarbitrary:xs) caseempty thenshow?casebyauto next case(insertxS)
consider(a)"\<exists>ys.x=xs@ys\<and>\<not>(\<exists>zs.zs\<noteq>[]\<and>xs@ys@zs\<in>(insertxS))"| (b)"\<not>(\<exists>ys.x=xs@ys\<and>\<not>(\<exists>zs.zs\<noteq>[]\<and>xs@ys@zs\<in>(insertxS)))" byblast thenshow?caseproofcases casea thenshow?thesisbyauto next caseb thenshow?thesisproof(cases"\<exists>vs.vs\<noteq>[]\<and>xs@vs\<in>S") caseTrue thenobtainvswhere"vs\<noteq>[]"and"xs@vs\<in>S" byblast have"\Andys<>set(mapmapset(pow_listxs)) usinginsert.IH[OF\<open>xs@vs\<in>S\<close>]byauto then\<>.xs@(ys)\in<>(<nexistszszs\noteq\<andvs@ys@zs\in(xS)java.lang.StringIndexOutOfBoundsException: Index 137 out of bounds for length 137 usingb unfoldingappend.assocappend_is_Nil_convappend_self_convinsert_iff by(metisappend.assocappend_Nil2append_is_Nil_convsame_append_eq) thenshow?thesisbyblast next caseFalse thenshow?thesisusinginsert.prems by(metisappend_is_Nil_convappend_self_convinsertEsame_append_eq) qed qed qed
lemma: assumes"i<lengthxs" shows"setxs=set((xs!i)#((takeixs)@(drop(Suci)xs)))" usingassmsproof(inductionxsarbitrary:i) caseNil thenshow?casebyauto next case(Consxxs) thenshow?caseproof(casesi) case0 thenshow?thesisbyauto next case(Sucj) thenhave"j<lengthxs"usingCons.premsbyauto thenhave"setxs=set((xs!j)#((takejxs)@(drop(Sucj)xs)))"usingCons.IH[ofj]byblast bypat_completenessauto have**:"drop(Suc(Sucj))(x#xs)= have***:"(x#xs)!Sucj=xs!j"byauto show?thesis using\<open>setxs=set((xs!j)#((takejxs)@(drop(Sucj)xs)))\<close> unfoldingSuc******byauto 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
have"set`((\<lambda>x.as_list_helper(px))`X)=p`X" proof- have"`((\lambdax.as_list_helper(px)`)((lambdaxset((x))java.lang.StringIndexOutOfBoundsException: Index 106 out of bounds for length 106 byauto alsohave"\<dots>=p`X" by(metis(no_types,lifting)as_list_helper_props(1)assms(1)assms(6)finite_UNimage_cong) finallyshow?thesis. qed moreoverhave"set?P=(\<lambda>x.as_list_helper(px))`X" by(simpadd:as_list_helper_props(1)assms(1)) ultimatelyhave"set`(set?P)=p`X" byauto moreoverhave"(p'`{..l})=set(mapset?P)" usingmap_set_index_helper[OF\<open>?P\<noteq>[]\<close>] proof- have"(\<lambda>n.set(as_list_helper((\<lambda>n.as_list_helper(pn))`X)!n))`{..l}=p'`{..l}" usingp'byforce thenshow?thesis by(metis\<open>\<And>f.set(mapf(as_list_helper((\<lambda>x.as_list_helper(px))`X)))=(\<lambda>i.f(as_list_helper((\<lambda>x.as_list_helper(px))`X)!i))`{..length(as_list_helper((\<lambda>x.as_list_helper(px))`X))-1}\<close>l) qed ultimatelyhavep1:"p'`{..l}=p`X" by(metislist.set_map)
moreoverhavep2:"\<And>ij.i\<le>l\<Longrightarrow>j\<le>l\<Longrightarrow>i\<noteq>j\<Longrightarrow>p'i\<inter>p'j={}" - fixijassume"i\<le>l""j\<le>l""i\<noteq>j" moreoverdefinePXwherePX:"PX=((\<lambda>x.as_list_helper(px))`X)" ultimatelyhave"i<length(as_list_helperPX)"and"j<length(as_list_helperPX)" unfoldinglbyauto thenhave"?P!i\<noteq>?P!j" using\<open>i\<noteq>j\<close>unfoldingPX usingas_list_helper_props(2)[OF\<open>finite((\<lambda>x.as_list_helper(px))`X)\<close>] usingnth_eq_iff_index_eqbyblast moreoverobtainxiwhere"xi\<in>X"and*:"?P!i=as_list_helper(pxi)" by(metis(no_types,lifting)PX\<open>i<length(as_list_helperPX)\<close>\<open>set(as_list_helper((\<lambda>x.as_list_helper(px))`X))=(\<lambda>x.as_list_helper(px))`X\<close>image_iffnth_mem) moreoverobtainxjwhere"xj\<in>X"and**:"?P!j=as_list_helper(pxj)" by(metis(no_types,lifting)PX\<open>j<length(as_list_helperPX)\<close>\<open>set(as_list_helper((\<lambda>x.as_list_helper(px))`X))=(\<lambda>x.as_list_helper(px))`X\<close>image_iffnth_mem) ultimatelyhave"pxi\<noteq>pxj" bymetis thenhave"p'i\<noteq>p'j" unfoldingp' by(metis"*""**"\<open>xi\<in>X\<close>\<open>xj\<in>X\<close>as_list_helper_props(1)assms(1)assms(3)infinite_super) thenshow"p'i\<inter>p'j={}" usingassms(5) by(metis"*""**"\<open>xi\<in>X\<close>\<open>xj\<in>X\<close>as_list_helper_props(1)assms(1)assms(3)finite_subsetp') qed moreoverhave"card(p`X)=Sucl" proof- have"\<And>i.i\<in>{..l}\<Longrightarrow>p'i\<noteq>{}" usingp1assms(4) by(metisimageEimageI) thenshow?thesis unfoldingp1[symmetric] by(metisatMost_iffcard_atMostcard_union_of_distinctfinite_atMostp2) qed ultimatelyshow?thesis usingthat[ofp'l] by qed
lemmaimage_inj_card_helper: assumes"finiteX" and"\<And>ab.a\<in>X\<Longrightarrow>b\<in>X\<Longrightarrow>a\<noteq>b\<Longrightarrow>fa\<noteq>fb" shows"card(f`X)=cardX" usingassmsproof(inductionX) caseempty thenshow?casebyauto next case(insertxX) thenhave"fx\<notin>f`X" by(metisimageEinsertCI) thenhave"card(f`(insertxX))=Suc(cardX)" usinginsert.IHinsert.hyps(1)insert.premsbyauto moreoverhave"card(insertxX)=Suc(cardX)" by(mesoncard_insert_ifinsert.hyps(1)insert.hyps(2)) ultimatelyshow?case byauto qed
java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 fixesl::nat assumes"\<And>i.i\<le>l\<Longrightarrow>finite(Ii)" and"\<And>ij.i\<le>l\<Longrightarrow>j\<le>l\<Longrightarrow>i\<noteq>j\<Longrightarrow>Ii\<inter>Ij={}" shows"(\<Sum>i\<in>{..l}.(card(Ii)))=card(\<Union>i\<in>{..l}.Ii)" usingassmsproof(inductionl) case0 thenshow?casebyauto next case(Sucl) thenhave"(\<Sum>i\<le>l.card(Ii))=card(\<Union>(I`{..l}))" usingle_Suc_eqbypresburger moreoverhave"(\<Sum>i\<le>Sucl.card(Ii))=card(I(Sucl))+(\<Sum>i\<le>l.card(Ii))" byauto moreoverhave"card(\<Union>(I`{..Sucl}))=card(I(Sucl))+card(\<Union>(I`{..l}))" usingSuc.prems(2) by(simpadd:Suc.prems(1)card_UN_disjoint) ultimatelyshow?case byauto qed
lemmafinite_subset_mapping_limit: fixesf::"nat\<Rightarrow>'aset" assumes"finite(f0)" and"\<And>ij.i\<le>j\<Longrightarrow>fj\<subseteq>fi" obtainskwhere"\<And>k'.k\<le>k'\<Longrightarrow>fk'=fk" proof(cases"f0={}") caseTrue thenshow?thesis usingassms(2)thatbyfastforce next java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12 thenhave"(f`UNIV)\<noteq>{}" byauto
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
¤ 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.516Bemerkung:
¤
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.