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)"
lemma separate_by_code[code] : "separate_by P xs = foldr (λx (prevPass,prevFail) . if P x then (x#prevPass,prevFail) else (prevPass,x#prevFail)) xs ([],[])" proof (induction xs) case Nil thenshow ?caseby auto next case (Cons a xs)
let ?f = "(λx (prevPass,prevFail) . if P x then (x#prevPass,prevFail) else (prevPass,x#prevFail))"
have"(filter P xs, filter (λ x . ¬ P x) xs) = foldr ?f xs ([],[])" using Cons.IH by auto moreoverhave"separate_by P (a#xs) = ?f a (filter P xs, filter (λ x . ¬ P x) xs)" by auto ultimatelyshow ?case by (cases "P a"; auto) qed
fun find_remove_2_all :: "('a ==> 'b ==> bool) ==> 'a list ==> 'b list ==> (('a × 'b) list × 'a list)"where "find_remove_2_all P xs ys = (map (λ x . (x, the (find (λy . P x y) ys))) (filter (λ x . find (λy . P x y) ys ≠ None) xs) ,filter (λ x . find (λy . P x y) ys = None) xs)"
fun find_remove_2_all' :: "('a ==> 'b ==> bool) ==> 'a list ==> 'b list ==> (('a ×'b) list × 'a list)"where "find_remove_2_all' P xs ys = (let (successesWithWitnesses,failures) = separate_by (λ(x,y) . y ≠ None) (map (λ x . (x,find (λy . P x y) ys)) xs) in (map (λ (x,y) . (x, the y)) successesWithWitnesses, map fst failures))"
lemma find_remove_2_all_code[code] : "find_remove_2_all P xs ys = find_remove_2_all' P xs ys" proof - let ?s1 = "map (λ x . (x, the (find (λy . P x y) ys))) (filter (λ x . find (λy . P x y) ys ≠ None) xs)" let ?f1 = "filter (λ x . find (λy . P x y) ys = None) xs"
let ?s2 = "map (λ (x,y) . (x, the y)) (filter (λ(x,y) . y ≠ None) (map (λ x . (x,find (λy . P x y) ys)) xs))" let ?f2 = "map fst (filter (λ(x,y) . y = None) (map (λ x . (x,find (λy . P x y) ys)) xs))"
have"find_remove_2_all P xs ys = (?s1,?f1)" by simp moreoverhave"find_remove_2_all' P xs ys = (?s2,?f2)" proof - have"∀p. (λpa. ¬ (case pa of (a::'a, x::'b option) ==> p x)) = (λ(a, z). ¬ p z)" by force thenshow ?thesis unfolding find_remove_2_all'.simps Let_def separate_by.simps by force qed moreoverhave"?s1 = ?s2" by (induction xs; auto) moreoverhave"?f1 = ?f2" by (induction xs; auto) ultimatelyshow ?thesis by simp qed
subsection‹Set-Operations on Lists›
fun pow_list :: "'a list ==> 'a list list"where "pow_list [] = [[]]" | "pow_list (x#xs) = (let pxs = pow_list xs in pxs @ map (λ ys . x#ys) pxs)"
lemma pow_list_set : "set (map set (pow_list xs)) = Pow (set xs)" proof (induction xs) case Nil thenshow ?caseby auto next case (Cons x xs)
moreoverhave"set (map set (pow_list (x#xs))) = set (map set (pow_list xs)) ∪ (image (insert x) (set (map set (pow_list xs))))" proof - have"∧ ys . ys ∈ set (map set (pow_list (x#xs))) ==> ys ∈ set (map set (pow_list xs)) ∪ (image (insert x) (set (map set (pow_list xs))))" proof - fix ys assume"ys ∈ set (map set (pow_list (x#xs)))" then consider (a) "ys ∈ set (map set (pow_list xs))" |
(b) "ys ∈ set (map set (map ((#) x) (pow_list xs)))" unfolding pow_list.simps Let_def by auto thenshow"ys ∈ set (map set (pow_list xs)) ∪ (image (insert x) (set (map set (pow_list xs))))" by (cases; auto) qed moreoverhave"∧ ys . ys ∈ set (map set (pow_list xs)) ∪ (image (insert x) (set (map set (pow_list xs)))) ==> ys ∈ set (map set (pow_list (x#xs)))" proof - fix ys assume"ys ∈ set (map set (pow_list xs)) ∪ (image (insert x) (set (map set (pow_list xs))))" then consider (a) "ys ∈ set (map set (pow_list xs))" |
(b) "ys ∈ (image (insert x) (set (map set (pow_list xs))))" by blast thenshow"ys ∈ set (map set (pow_list (x#xs)))" unfolding pow_list.simps Let_def by (cases; auto) qed ultimatelyshow ?thesis by blast qed
ultimatelyshow ?case by auto qed
subsubsection‹Removing Subsets in a List of Sets›
lemma remove1_length : "x ∈ set xs ==> length (remove1 x xs) < length xs" by (induction xs; auto)
function remove_subsets :: "'a set list ==> 'a set list"where "remove_subsets [] = []" | "remove_subsets (x#xs) = (case find_remove (λ y . x ⊂ y) xs of Some (y',xs') ==> remove_subsets (y'# (filter (λ y . ¬(y ⊆ x)) xs')) | None ==> x # (remove_subsets (filter (λ y . ¬(y ⊆ x)) xs)))" by pat_completeness auto termination proof - have"∧x xs. find_remove ((⊂) x) xs = None ==> (filter (λy. ¬ y ⊆ x) xs, x # xs) ∈ measure length" by (metis dual_order.trans impossible_Cons in_measure length_filter_le not_le_imp_less) moreoverhave"(∧(x :: 'a set) xs x2 xa y. find_remove ((⊂) x) xs = Some x2 ==> (xa, y) = x2 ==> (xa # filter (λy. ¬ y ⊆ x) y, x # xs) ∈ measure length)" proof - fix x :: "'a set" fix xs y'xs' y' xs' assume"find_remove ((⊂) x) xs = Some y'xs'"and"(y', xs') = y'xs'" thenhave"find_remove ((⊂) x) xs = Some (y',xs')" by auto
have"length xs' = length xs - 1" using find_remove_set(2,3)[OF ‹find_remove ((⊂) x) xs = Some (y',xs')›] by (simp add: length_remove1) thenhave"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 (λy. ¬ y ⊆ x) xs') ≤ length xs'" by simp thenhave"length (y' # filter (λy. ¬ y ⊆ x) xs') ≤ length xs' + 1" by simp thenhave"length (y' # filter (λy. ¬ y ⊆ x) xs') ≤ length xs" unfolding‹length (y'#xs') = length xs›[symmetric] by simp thenshow"(y' # filter (λy. ¬ y ⊆ x) xs', x # xs) ∈ measure length" by auto qed ultimatelyshow ?thesis by (relation "measure length"; auto) qed
lemma remove_subsets_set : "set (remove_subsets xss) = {xs . xs ∈ set xss ∧ (∄ xs' . xs' ∈ set xss ∧ xs ⊂ xs')}" proof (induction"length xss" arbitrary: xss rule: less_induct) case less
show ?caseproof (cases xss)
case Nil thenshow ?thesis by auto next case (Cons x xss')
show ?thesis proof (cases "find_remove (λ y . x ⊂ y) xss'") case None thenhave"(∄ xs' . xs' ∈ set xss' ∧ x ⊂ xs')" using find_remove_None_iff by metis
have"length (filter (λ y . ¬(y ⊆ x)) xss') < length xss" using Cons by (meson dual_order.trans impossible_Cons leI length_filter_le)
have"remove_subsets (x#xss') = x # (remove_subsets (filter (λ y . ¬(y ⊆ x)) xss'))" using None by auto thenhave"set (remove_subsets (x#xss')) = insert x {xs ∈ set (filter (λy. ¬ y ⊆ x) xss'). ∄xs'. xs' ∈ set (filter (λy. ¬ y ⊆ x) xss') ∧ xs ⊂ xs'}" using less[OF ‹length (filter (λ y . ¬(y ⊆ x)) xss') < length xss›] by auto alsohave"… = {xs . xs ∈ set (x#xss') ∧ (∄ xs' . xs' ∈ set (x#xss') ∧ xs ⊂ xs')}" proof - have"∧ xs . xs ∈ insert x {xs ∈ set (filter (λy. ¬ y ⊆ x) xss'). ∄xs'. xs' ∈ set (filter (λy. ¬ y ⊆ x) xss') ∧ xs ⊂ xs'} ==> xs ∈ {xs ∈ set (x # xss'). ∄xs'. xs' ∈ set (x # xss') ∧ xs ⊂ xs'}" proof - fix xs assume"xs ∈ insert x {xs ∈ set (filter (λy. ¬ y ⊆ x) xss'). ∄xs'. xs' ∈ set (filter (λy. ¬ y ⊆ x) xss') ∧ xs ⊂ xs'}" then consider "xs = x" | "xs ∈ set (filter (λy. ¬ y ⊆ x) xss') ∧ (∄xs'. xs' ∈ set (filter (λy. ¬ y ⊆ x) xss') ∧ xs ⊂ xs')" by blast thenshow"xs ∈ {xs ∈ set (x # xss'). ∄xs'. xs' ∈ set (x # xss') ∧ xs ⊂ xs'}" using‹(∄ xs' . xs' ∈ set xss' ∧ x ⊂ xs')›by (cases; auto) qed moreoverhave"∧ xs . xs ∈ {xs ∈ set (x # xss'). ∄xs'. xs' ∈ set (x # xss') ∧ xs ⊂ xs'} ==> xs ∈ insert x {xs ∈ set (filter (λy. ¬ y ⊆ x) xss'). ∄xs'. xs' ∈ set (filter (λy. ¬ y ⊆ x) xss') ∧ xs ⊂ xs'}" proof - fix xs assume"xs ∈ {xs ∈ set (x # xss'). ∄xs'. xs' ∈ set (x # xss') ∧ xs ⊂ xs'}" thenhave"xs ∈ set (x # xss')"and"∄xs'. xs' ∈ set (x # xss') ∧ xs ⊂ xs'" by blast+ then consider "xs = x" | "xs ∈ set xss'"by auto thenshow"xs ∈ insert x {xs ∈ set (filter (λy. ¬ y ⊆ x) xss'). ∄xs'. xs' ∈ set (filter (λy. ¬ y ⊆ x) xss') ∧ xs ⊂ xs'}" proof cases case1 thenshow ?thesis by auto next case2 show ?thesis proof (cases "xs ⊆ x") case True thenshow ?thesis using‹∄xs'. xs' ∈ set (x # xss') ∧ xs ⊂ xs'›by auto next case False thenhave"xs ∈ set (filter (λy. ¬ y ⊆ x) xss')" using2by auto moreoverhave"∄xs'. xs' ∈ set (filter (λy. ¬ y ⊆ x) xss') ∧ xs ⊂ xs'" using‹∄xs'. xs' ∈ set (x # xss') ∧ xs ⊂ xs'›by auto ultimatelyshow ?thesis by auto qed qed qed ultimatelyshow ?thesis by (meson subset_antisym subset_eq) qed finallyshow ?thesis unfolding Cons[symmetric] by assumption next case (Some a) thenobtain y' xs' where *: "find_remove (λ y . x ⊂ y) xss' = Some (y',xs')"by force
have"length xs' = length xss' - 1" using find_remove_set(2,3)[OF *] by (simp add: length_remove1) thenhave"length (y'#xs') = length xss'" using find_remove_set(2)[OF *] using remove1_length by fastforce
have"length (filter (λy. ¬ y ⊆ x) xs') ≤ length xs'" by simp thenhave"length (y' # filter (λy. ¬ y ⊆ x) xs') ≤ length xs' + 1" by simp thenhave"length (y' # filter (λy. ¬ y ⊆ x) xs') ≤ length xss'" unfolding‹length (y'#xs') = length xss'›[symmetric] by simp thenhave"length (y' # filter (λy. ¬ y ⊆ x) xs') < length xss" unfolding Cons by auto
have"remove_subsets (x#xss') = remove_subsets (y'# (filter (λ y . ¬(y ⊆ x)) xs'))" using * by auto thenhave"set (remove_subsets (x#xss')) = {xs ∈ set (y' # filter (λy. ¬ y ⊆ x) xs'). ∄xs'a. xs'a ∈ set (y' # filter (λy. ¬ y ⊆ x) xs') ∧ xs ⊂ xs'a}" using less[OF ‹length (y' # filter (λy. ¬ y ⊆ x) xs') < length xss›] by auto alsohave"… = {xs . xs ∈ set (x#xss') ∧ (∄ xs' . xs' ∈ set (x#xss') ∧ xs ⊂ xs')}" proof - have"∧ xs . xs ∈ {xs ∈ set (y' # filter (λy. ¬ y ⊆ x) xs'). ∄xs'a. xs'a ∈ set (y' # filter (λy. ¬ y ⊆ x) xs') ∧ xs ⊂ xs'a} ==> xs ∈ {xs ∈ set (x # xss'). ∄xs'. xs' ∈ set (x # xss') ∧ xs ⊂ xs'}" proof - fix xs assume"xs ∈ {xs ∈ set (y' # filter (λy. ¬ y ⊆ x) xs'). ∄xs'a. xs'a ∈ set (y' # filter (λy. ¬ y ⊆ x) xs') ∧ xs ⊂ xs'a}" thenhave"xs ∈ set (y' # filter (λy. ¬ y ⊆ x) xs')"and"∄xs'a. xs'a ∈ set (y' # filter (λy. ¬ y ⊆ x) xs') ∧ xs ⊂ xs'a" by blast+
have"xs ∈ set (x # xss')" using‹xs ∈ set (y' # filter (λy. ¬ y ⊆ x) xs')› find_remove_set(2,3)[OF *] by auto moreoverhave"∄xs'. xs' ∈ set (x # xss') ∧ xs ⊂ xs'" using‹∄xs'a. xs'a ∈ set (y' # filter (λy. ¬ y ⊆ x) xs') ∧ xs ⊂ xs'a› find_remove_set[OF *] by (metis dual_order.strict_trans filter_list_set in_set_remove1 list.set_intros(1) list.set_intros(2) psubsetI set_ConsD) ultimatelyshow"xs ∈ {xs ∈ set (x # xss'). ∄xs'. xs' ∈ set (x # xss') ∧ xs ⊂ xs'}" by blast qed moreoverhave"∧ xs . xs ∈ {xs ∈ set (x # xss'). ∄xs'. xs' ∈ set (x # xss') ∧ xs ⊂ xs'} ==> xs ∈ {xs ∈ set (y' # filter (λy. ¬ y ⊆ x) xs'). ∄xs'a. xs'a ∈ set (y' # filter (λy. ¬ y ⊆ x) xs') ∧ xs ⊂ xs'a}" proof - fix xs assume"xs ∈ {xs ∈ set (x # xss'). ∄xs'. xs' ∈ set (x # xss') ∧ xs ⊂ xs'}" thenhave"xs ∈ set (x # xss')"and"∄xs'. xs' ∈ set (x # xss') ∧ xs ⊂ xs'" by blast+
thenhave"xs ∈ set (y' # filter (λy. ¬ y ⊆ x) xs')" using find_remove_set[OF *] by (metis filter_list_set in_set_remove1 list.set_intros(1) list.set_intros(2) psubsetI set_ConsD) moreoverhave"∄xs'a. xs'a ∈ set (y' # filter (λy. ¬ y ⊆ x) xs') ∧ xs ⊂ xs'a" using‹xs ∈ set (x # xss')›‹∄xs'. xs' ∈ set (x # xss') ∧ xs ⊂ xs'› find_remove_set[OF *] by (metis filter_is_subset list.set_intros(2) notin_set_remove1 set_ConsD subset_iff) ultimatelyshow"xs ∈ {xs ∈ set (y' # filter (λy. ¬ y ⊆ x) xs'). ∄xs'a. xs'a ∈ set (y' # filter (λy. ¬ y ⊆ x) xs') ∧ xs ⊂ xs'a}" by blast qed ultimatelyshow ?thesis by blast qed finallyshow ?thesis unfolding Cons by assumption qed qed qed
subsection‹Linear Order on Sum›
instantiation sum :: (ord,ord) ord begin
fun less_eq_sum :: "'a + 'b ==> 'a + 'b ==> bool"where "less_eq_sum (Inl a) (Inl b) = (a ≤ b)" | "less_eq_sum (Inl a) (Inr b) = True" | "less_eq_sum (Inr a) (Inl b) = False" | "less_eq_sum (Inr a) (Inr b) = (a ≤ b)"
fun less_sum :: "'a + 'b ==> 'a + 'b ==> bool"where "less_sum a b = (a ≤ b ∧ a ≠ b)"
instanceby (intro_classes) end
instantiation sum :: (linorder,linorder) linorder begin
lemma less_le_not_le_sum : fixes x :: "'a + 'b" and y :: "'a + 'b" shows"(x < y) = (x ≤ y ∧¬ y ≤ x)" by (cases x; cases y; auto)
lemma order_refl_sum : fixes x :: "'a + 'b" shows"x ≤ x" by (cases x; auto)
lemma order_trans_sum : fixes x :: "'a + 'b" fixes y :: "'a + 'b" fixes z :: "'a + 'b" shows"x ≤ y ==> y ≤ z ==> x ≤ z" by (cases x; cases y; cases z; auto)
lemma antisym_sum : fixes x :: "'a + 'b" fixes y :: "'a + 'b" shows"x ≤ y ==> y ≤ x ==> x = y" by (cases x; cases y; auto)
lemma linear_sum : fixes x :: "'a + 'b" fixes y :: "'a + 'b" shows"x ≤ y ∨ y ≤ x" by (cases x; cases y; auto)
instance using less_le_not_le_sum order_refl_sum order_trans_sum antisym_sum linear_sum by (intro_classes; metis+) end
subsection‹Removing Proper Prefixes›
definition remove_proper_prefixes :: "'a list set ==> 'a list set"where "remove_proper_prefixes xs = {x . x ∈ xs ∧ (∄ x' . x' ≠ [] ∧ x@x' ∈ xs)}"
lemma remove_proper_prefixes_code[code] : "remove_proper_prefixes (set xs) = set (filter (λx . (∀ y ∈ set xs . is_prefix x y ⟶ x = y)) xs)" proof -
have *: "remove_proper_prefixes (set xs) = Set.filter (λ zs . ∄ys . ys ≠ [] ∧ zs @ ys ∈ (set xs)) (set xs)" unfolding remove_proper_prefixes_def by force
have *:"set (sorted_list_of_set xs) = xs" by (simp add: assms)
have"∧x y . x∈xs ==> y∈xs ==> assign_indices xs x = assign_indices xs y ==> x = y" proof - fix x y assume"x∈xs"and"y∈xs"and"assign_indices xs x = assign_indices xs y"
obtain i where"find_index ((=)x) (sorted_list_of_set xs) = Some i" using find_index_exhaustive[of "sorted_list_of_set xs""((=) x)"] using‹x∈xs›unfolding * by blast thenhave"assign_indices xs x = i" by auto
obtain j where"find_index ((=)y) (sorted_list_of_set xs) = Some j" using find_index_exhaustive[of "sorted_list_of_set xs""((=) y)"] using‹y∈xs›unfolding * by blast thenhave"assign_indices xs y = j" by auto thenhave"i = j" using‹assign_indices xs x = assign_indices xs y›‹assign_indices xs x = i› by auto thenhave"find_index ((=)y) (sorted_list_of_set xs) = Some i" using‹find_index ((=)y) (sorted_list_of_set xs) = Some j› by auto
show"x = y" using find_index_index(2)[OF ‹find_index ((=)x) (sorted_list_of_set xs) = Some i›] using find_index_index(2)[OF ‹find_index ((=)y) (sorted_list_of_set xs) = Some i›] by auto qed moreoverhave"(assign_indices xs) ` xs = {..<card xs}" proof show"assign_indices xs ` xs ⊆ {..<card xs}" proof fix i assume"i ∈ assign_indices xs ` xs" thenobtain x where"x ∈ xs"and"i = assign_indices xs x" by blast moreoverobtain j where"find_index ((=)x) (sorted_list_of_set xs) = Some j" using find_index_exhaustive[of "sorted_list_of_set xs""((=) x)"] using‹x∈xs›unfolding * by blast ultimatelyhave"find_index ((=)x) (sorted_list_of_set xs) = Some i" by auto show"i ∈ {..<card xs}" using find_index_index(1)[OF ‹find_index ((=)x) (sorted_list_of_set xs) = Some i›] by auto qed show"{..<card xs} ⊆ assign_indices xs ` xs" proof fix i assume"i ∈ {..<card xs}" thenhave"i < length (sorted_list_of_set xs)" by auto thenhave"sorted_list_of_set xs ! i ∈ xs" using"*" nth_mem by blast thenobtain j where"find_index ((=) (sorted_list_of_set xs ! i)) (sorted_list_of_set xs) = Some j" using find_index_exhaustive[of "sorted_list_of_set xs""((=) (sorted_list_of_set xs ! i))"] unfolding * by blast have"i = j" using find_index_index(1,2)[OF ‹find_index ((=) (sorted_list_of_set xs ! i)) (sorted_list_of_set xs) = Some j›] using‹i < length (sorted_list_of_set xs)› distinct_sorted_list_of_set nth_eq_iff_index_eq by blast thenshow"i ∈ assign_indices xs ` xs" using‹find_index ((=) (sorted_list_of_set xs ! i)) (sorted_list_of_set xs) = Some j› by (metis ‹sorted_list_of_set xs ! i ∈ xs› assign_indices.elims image_iff option.sel) qed qed ultimatelyshow ?thesis unfolding bij_betw_def inj_on_def by blast qed
subsection‹Other Lemmata›
lemma foldr_elem_check: assumes"list.set xs ⊆ A" shows"foldr (λ x y . if x ∉ A then y else f x y) xs v = foldr f xs v" using assms by (induction xs; auto)
lemma foldl_elem_check: assumes"list.set xs ⊆ A" shows"foldl (λ y x . if x ∉ A then y else f y x) v xs = foldl f v xs" using assms by (induction xs rule: rev_induct; auto)
lemma foldr_length_helper : assumes"length xs = length ys" shows"foldr (λ_ x . f x) xs b = foldr (λa x . f x) ys b" using assms by (induction xs ys rule: list_induct2; auto)
lemma list_append_subset3 : "set xs1 ⊆ set ys1 ==> set xs2 ⊆ set ys2 ==> set xs3 ⊆set ys3 ==> set (xs1@xs2@xs3) ⊆ set(ys1@ys2@ys3)"by auto
lemma subset_filter : "set xs ⊆ set ys ==> set xs = set (filter (λ x . x ∈ set xs) ys)" by auto
lemma map_filter_elem : assumes"y ∈ set (List.map_filter f xs)" obtains x where"x ∈ set xs" and"f x = Some y" using assms unfolding List.map_filter_def by auto
lemma filter_length_weakening : assumes"∧ q . f1 q ==> f2 q" shows"length (filter f1 p) ≤ length (filter f2 p)" proof (induction p) case Nil thenshow ?caseby auto next case (Cons a p) thenshow ?caseusing assms by (cases "f1 a"; auto) qed
lemma max_length_elem : fixes xs :: "'a list set" assumes"finite xs" and"xs ≠ {}" shows"∃ x ∈ xs . ¬(∃ y ∈ xs . length y > length x)" using assms proof (induction xs) case empty thenshow ?caseby auto next case (insert x F) thenshow ?caseproof (cases "F = {}") case True thenshow ?thesis by blast next case False thenobtain y where"y ∈ F"and"¬(∃ y' ∈ F . length y' > length y)" using insert.IH by blast thenshow ?thesis using dual_order.strict_trans by (cases "length x > length y"; auto) qed qed
lemma min_length_elem : fixes xs :: "'a list set" assumes"finite xs" and"xs ≠ {}" shows"∃ x ∈ xs . ¬(∃ y ∈ xs . length y < length x)" using assms proof (induction xs) case empty thenshow ?caseby auto next case (insert x F) thenshow ?caseproof (cases "F = {}") case True thenshow ?thesis by blast next case False thenobtain y where"y ∈ F"and"¬(∃ y' ∈ F . length y' < length y)" using insert.IH by blast thenshow ?thesis using dual_order.strict_trans by (cases "length x < length y"; auto) qed qed
lemma list_property_from_index_property : assumes"∧ i . i < length xs ==> P (xs ! i)" shows"∧ x . x ∈ set xs ==> P x" by (metis assms in_set_conv_nth)
lemma list_distinct_prefix : assumes"∧ xs ==> xs ! i ∉ set (take i xs)" showsset proof - have"∧a "< min_maxsimpchain" proof - fix j show "distinct (take j xs)" proof (induction j) 0 then slem pgalle paia_f case (Suc j) then shw ?as oo (ae S <> legt x" case True thenhave"take "ubcomplexamberSubcomplex_def
e_eqc_conv_app_nth
mber ChamberComplex.gallery Y Cs gallery Cs" lse chamber_facet_is_chamber_facet then sho ?thsiss usngg Su.IH b autt qed qed
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 then have "distinct (take by thenshow ?thesis by auto qed
lemma concat_pair_set "set (concat (map (\lambdax. map (Pair x) ys) xs)) = {xy . fst xy ∈ set xs ∧ snd xy ∈ set ys}" by
emma
yet
lemma list_contains_last_take assumes"x ∈ s< i . 0 < i ∧ i ≤ length xs ∧ last (take i xs) = x" by (metis Suc_leI assms hd_drop_conv_nth in_set_conv_nth last_snoc take_hd_drop zero_less_Suc)
lemma assumeshave (<>))" shows "a = (LEAST x . P x)" (metis Coltemt_ Latuly ssinetnt_tym_Cllc_q de_elsnlen)
lemma sort_list_split : < x ∈ set (take i (sort xs)) . ∀ y ∈ set (drop i (sort xs)) . x ≤" using sorted_append by fastforce
lemma assumes"x ∈on neo (<>X) \Longrightarrow>hmColxrpim and rule Cham.aios), ul smuollle shows "tqed using
lemma rev_induct2[s,e_namesil assumes"length xs = length ys"
[ "And>x xsy.leghx=ent s\Longrightarrow>P sy <ghrrwPx@x] y@]) shows "P xs_<>UnionX ==><>∪ using assms proofusingtetrel_cardCjava.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55 case Nil thenshow ? yjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25 next case (snoc x xs) thencasefcases case Nil
showthesis
ngrems next case (Cons a list)
en
ysend_butlast_last_idtonhyps by qed
lemma finite_set_min_param_ex assumes"finite XS" and\ XS ==> k . ∀ k' ⟶" shows "∃X" "SimplicialComplex.maxsimp (\turnstile proof - "C<>codomain.chamber (f`C) ==> " using assms(2) by meson let ?k=ax have"∀X""x = f`zx""zy∈ using f_def by (simp add: assms(1)) then show ?thesis by blast qed
fun list_max :: "nat list ==> nat" where "list_max [] = 0 "list_max xs = Max (set xs)"
lemmast_prefix_subset <>ys t= @s Longrig set xs ⊆ set ts"by auto lemma list_map_set_prop : "x ∈ set (map f xs) ==>∀ y . P (f y) ==> lemma list_concat_non_elem : "\notin set xs ==> set ys ==> set (xs@ys)" by auto lemma list_prefix_e gallery_betw[O oanglyeslnt,of ] lemma list_map_source_elem : "x ∈ <existssts set fx' auto
lemmaver fixes X :: "'a set set" assumes"finite X" and X" showsfixespointwisegc>f) (\UnionX)""fixespointwise (f∘Y)" proof (rule assume"¬S'∈ S' ∧S''∈ S' \<ubsetset then have *: "∧ by auto
have"∧ of < ss . (length ss = Suc k) ∧ (hd ss = S) ∧ (∀ i < k . ss ! i ⊂ ss ! (Suc i)) ∧ (set ss ⊆ X)"
_ case0
ll . [S] ! i ⊂ [S] ! (Suc i)) ∧ X)" using assms(2) by auto nwcs b lt next case (SufixC sm "amber thene_inv_intoX) f ` C ∈ andqed and andmoreover=
t
e \>X by auto moreoverhave"S ⊆ proof - ">i . i < Suc k ==> (ss ! i)" proof - fix aumei< how su> (ss ! i)" proof (induction i) case0
shownghd ss = S›‹ by(metishd_conv_nthlist.size(3)nat.distinct(1)order_refl) next case(Suci) ave\subseteq>ssnd<k"byauto thenhave"ss!i\<subset> thenshow?caseusing qed qed thenshow?thesisusing\<open>lengthss=Suck\<close>adj_mapjava.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40 qed ultimatelyobtainfromassmsamberComplexMorphismf)" using*bymeson
let?ss="ss@[T']"
have"length?ss=Suclemmafunpower_endomorphism <lengthss=Suck\<close>byauto veresS using\<open>hdss=S\<close>by(metis\<qed moreoverhave"(\<hence"mberComplexEndomorphism<>fjava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62 using\<open>(\<forall>i<k.ss!i\<subset>ss!Suci)\<close>\<open>ss!k\<subset\existsAsABBs.A\<in>f\<turnstile>\<C>\<and>B\<in>\<C>-f\<turnstile>\<C>\<and>C#Cs@[D]=As@A#B#" by(metisSuc_lessI\<open>lengthss=Suck\<close>diff_Suc_1less_SucEnth_appendnth_append_length) moreoverhave"set?ss\<subseteq>X" using\<open>setss\<subseteq>X\<close>\<open>Tlabel_wrt_adjacent(wEN]stforce ultimatelyshow?caseinductbitrarylev_induct qed qed
thenobtainsswhere"(lengthss(" " and(forall<cardX.ss!i\<subset>ss!(Suci))" and"(setss\<subseteq>X)" byblast inerComplexal_automorphism java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
have**:"\<And>i(ss::'asetlist).(\<forall>i<lengthss-1.ss!i\<subset>ss!(Suci))\<Longrightarrow>i<lengthss\<Longrightarrow>\<forall>s\<in>set(takeiss).s\<subset>ss!i" proof- fixi fixss::"'asetlist" assume"i<lengthss"and"(\<forall>i<lengthss-1.ssusingial_outsideberComplexAutomorphismsmivial_outsidevial_outsidems thenshow"\<forall>s\<in>set(takeiss).rivial_outsidesideF() proof(inductiontext<openAretractionofachambercomplexisanendomorphismthatistheidentityonitsimage.\<close> 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)"maxsimp_connect`"]amber_retraction1C" by(metis> moreoverhave"ssactionnndiqueambereroutsidedege
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 by(simpadd:take_Suc_conv_app_nth) ultimatelyshow?casebyauto qed ed
have"distinctss" sing<open>(\<forall<lengthss-1.ss!i\<subset>ss!(Suci))\<close> proof caseNil thenshow?casebyauto next case(snocass) fromsnoc.premshave"\<-
thenhave"distinctssjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11 usingsnoc.IHbyauto moreovereravea<>tsjava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37 using**[OFsnoc.prems,of"length(ss@[a])-byuto ultimatelyshow?casebyauto qedchamberD_simplexmapptoo
ardXjava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42 using\<open>(lengthss=Suc(cardX)closeby(simpadd:distinct_card) thenshow"False" singg<openets<subseteq>X\close\<pen>initenitetecloseby(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) showe{<>X-<>D}" caseTrue thenhave"distinct(take(lengthxs)(xs@[x]))"byauto moreoverhave"\<notdistinct(akeengthxs)xs@)ingsnoccs)byto ultimatelydjacentset_conv_facetchambersetsssimp next caseFalse by(metisSuc_monobutlast_snoclength_append_singletonless_SucIlinorder_not_lesnoc.prems(stforcece qed qed
lemmalist_index_fun_gt:"\<And>xs(f::'a\<Rightarrow>nat)ij. (\<diuclengthxs\<Longrightarrow>f(xs!i)>f(xs!(Suci))) \<Longrightarrow>j<i \<Longrightarrowj_chamber \<Longrightarrow proof- fixxs::"'alist" fixf::"'a\<Rightarrow>nat" fixij assume"(\<And>i.ComplexMorphism and"j<i" and"i<lengthxs" thenshow"f(xs!j)>f(xs!i)" proof(induction"i-j"arbitrary:ij) chambersrs(,5:"gfD" thenhow?uto next case(Sucx) thenshow?case proof- havef1:"\<forall>n.\<not>Sucn<yD_adjFW()] usingSuc.prems(1)bypresburger
java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 66 usingSuc_leIbysatx have"x=i-Sucjava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26 by(metis(rulenI thenhave"\<not>Sucj<i\<or>fxs<f(xs!Sucj)" yastt thenshow?thesis usingf2f1by(metisSuc.prems(2)Suc.ssmsChamberComplexIsomorphism qed qed qed
lemmafinite_set_elem_maximal_extension_ex: assumes"<in>S" and"finiteS" shows"\<exists>ys.xs@ys\<in>S\<and>\< 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<>(>zs.zs\<noteq>[]\<and>xs@ys@zs\<in>(insertxS))"| (bB=B"andfA:"="nd:"`Ejava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59 byblast ingllery_mapery_mapap##FsD"gallery_Cons_reduce caseesrev_casesses thenshow?thesisbyauto next caseb thenshow?thesisproof(cases"\<exists>vs.vs\qed caseTrue thenobtainvswhere"vs\<noteq>[]"and"xs@vs\<in>S" byblast have"\<exists>ys.xs@(vs@ys)\<in>S\<and>(\<nexists>zs.zs\<noteq>[]\<and>show"incloserToC" usinginsert.IH[OF\<open>xs@vs\<in>S\<close>]byauto thenhave"\<exists>ys.xs@(vs@ys)\<in>S\<and> usingb unfoldingappend.assocappend_is_Nil_convappend_self_convinsert_iff by(metisappend.assocappend_Nil2append_is_Nil_convy_Cons_reduceEs#@] thenshow?thesisbyblast next caseFalse thenshow?thesisusinginsert.prems yetisppend_is_Nil_convappend_self_convinsertEsame_append_eq) qed qed qed
lemmalist_index_split_set: assumes"i<lengthxs" shows"setxs=set((xs!i)#((take`B<noteq>f" usinghesis il thenshow?casebyauto next case(Consxxs) thenshow?caseproof(casesi) e thenshow?thesisbyauto next case(Sucj) thenhave"j<lengthxs"usingCons.premsbyauto thenhave"setxs=set((xs!)#((akexs)(ucxs"singngonsofbyblast have*:"take(Sucjf>x.SimplicialComplex.maxsimpYx\<and>y\<subseteq>x" have**:"drop(Suc(Sucj))(x#xs)=(drop(Sucj)xs)"byauto dinggpp_chambersfChamber_system_defystem_defm_def show?thesis using\<open>setxs=set((xs!j)#((takejxs)@(drop(Sucj unfoldingSuc******byauto qed qed
lemmacard_union_of_singletons: assumes"\<And>S.S\<in>SS\<Longrightarrow>(\<exists.t" shows"card(\<Union>SS)=cardSS" proof- let?f="\<lambda>x.{x}" have"ij_betw?f(<UnionSS))SS" unfoldingij_betw_deftw_defnj_on_defsingsmsbyfastforceforce thenshow?thesis usingbij_betw_same_cardbyblast qed
lemmacard_union_of_distinct: assumes"\<And>21\in>SS\<Longrightarrow>S2\<in>SS\<Longrightarrow>S1=S2orfS1\<inter>fS2={}" and"finiteSS" and"\<And>S.S\<in>SS\<Longrightarrow>fS\< shows"card(imagefSS)=cardSS" proofivial_C0l_C0:v\in>C0\<Longrightarrow>fv=v" fromassms(2)have"\<forall>S1\<in>SS.\<forall>S2\<in>SS.S1=S2\<or>fS1\<interjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 \<Longrightarrow>\<forall>S\<in>SS.fS>{}\<Longrightarrow>?thesis" proof(inductionSS) caseempty thenshow?casebyuto next case(insertxF) thenhave"\<not>(\<exists>y\<in>F.fy=fx)" byautowhereC<g\<turnstile>\<C>""a\<subseteq>C" thenhave"fx\<notin>imagefF" byauto thenhave"card(imagef(insertxF))=Suc(card(imagefF))" usinginsertbyauto moreoverhave"card(f`F)=cardF" usinginsertbyauto moreoverhave"card(insertxF)=Suc(cardF)" usinginsertaassume\<n><Union>X" ultimatelyowase bysimp qed thenshow?thesis usingassmsbysimp
java.lang.StringIndexOutOfBoundsException: Index 107 out of bounds for length 3
lemma
java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 21 and"split_gallery_gf and"\<And>x1y1y2.y1\<in>fx1\<Longrightarrow>y2\<in>fx1\<Longrightarrow>y1\<noteq>y2\<Longrightarrow>gy1\<inter>gy2={}" and"\<And> and"\<And>y1.finite(gy1)" and"\<And>y1.gy1\<subseteq>zs" and"finitezsfolding_ging_grtex_retraction shows"(\<Sum>x\<in>xs.card(\java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 proof- have"(\<Sum>x\<in>xs.card(\<Union>y(tntron_eq_onInI) usingassms(1,2)proofinduction caseempty thenshow?casebyauto next thenhave"(\<And>x1x2.x1\<in>xsbyto thenhave"(\<Sum>x\<in>xs.card(\<Union>(g`fqedp
moreoverhave"(\<Sum>x\<in>(insertxxs).card(\<Union>(g`fx)))=java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 usingertbyto
moreoverhave"card(\<Union>x\<in>(insertxxs).\<Union>(g`fxbyauto proofjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11 have"((\<Union>x\<in>xs.<Union>(`f)\<\<Union>(g`fx))=(\<Union>x\<in>(insertxxs).\<Union>(g`fx))" byblast
lemmafinite_snd_helper: assumes"finitexs" shows"finite{z.((q,p),z)\<in>xs}" proof- have"{z.((q,p),z)\<in>xs}\<subseteq>(\<lambda>((a,b),c).c)ThinChamberComplexFoldings proof fixxassume"x\<in>{z.((q,p),z)\<in>xs}" thenhave"((q,p),x)\<in>xs"byauto thenshow"x\<in>(\<lambda>((a,b),c).c)`xs"byforce qed thenshow?thesisusingassms usingfinite_surjbyblast qed
lemmafold_dual:"fold(\<lambda>x(a1,a2).(xa1g22)sa1fold1xs1fold2sa2java.lang.StringIndexOutOfBoundsException: Index 111 out of bounds for length 111 inductionsrbitrarya1a2auto
CConsConsD) case0 thenhave"x\<ge>k" qed thenshow?case usingassms(3)by(simpadd:assms(1,2)) next case(Suck') show?caseproof(cases"Px") caseTrue thenshow?thesisby(simpadd:assms(1,2)) next caseFalse moreoverhave"f1(Sucx)=f2(Sucx)" usingSuc.hyps(1)[ ultimatelyshow?thesisby(simpadd:assms(1,2)) qed qed qed
usingTrueunfolding\<openxclose>byauto next caseFalse thenhave"fx=f(java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 by(simpadd:assms(1)) then using\<open>P(f(Sucx))\<close>bysimp moreoverhave"(\<forall>x'\<ge>x.x'<fx\<longrightarrow>\<not>Px')" using\<open>\<And>x'.x'\<ge>Sucx\<Longrightarrow>x'<f(Sucx)\<Longrightarrow>\<not>Px'\<close>False\<open>fx=f(Sucx)\<close> by(metisSuc_leIle_neq_implies_less) ultimatelyshow?thesis byblast ed qed thenshow"P(fx)"and"\<And>x'.x'\<ge>x\<Longrightarrow>x'<fx\<Longrightarrow>\<not>Px'" byblast+ qed
lemmamap_set_index_helper: assumes"xs\<noteq>[]" shows"set(mapfxs)=(\<lambda>i.f(xs!i))`{..(lengthxs-1)}" singassmsproof(inductionxsrule:rev_induct) caseNil thenshow?casebyauto next case(snocxxs) show?caseproof(cases"xs=[]") caseTrue show usingsnoc.premsusingseparated_by_this_wall_fg_is_wall_gf next caseFalse
have"{..length(xs@[x])-1}=insert(length(xs@[x])-1){..lengthxs-1}" byforce moreoverf<nfoldpairs""H={f\<urnstile<C>turnstile\<C>}""C\<in>f\<turnstile>\<C>""D\<in>g\<turnstile>\" byauto moreoverhave"((\<lambda>i.f((xs@[x])!i))`{..lengthxs-1})=((\<lambda>i.f(xs!i))`{..lengthxs-1})" proof- have"\<And>i.i<lengthxs\<Longrightarrow>f((xs@[x])!i)=f(xs!i)" by(simpadd:nth_append) moreoverhave"\<And>i.i\<in>{..lengthxs-1}\<Longrightarrow>i<lengthxs" usingFalse by(metisSuc_pred'atMost_ifflength_greater_0_convless_Suc_eq_le) ultimatelyshow?thesis by(mesonimage_cong) qed ultimatelyhave"(\<lambda>i.f((xs@[x])!i))`{..length(xs@[x])-1}=insert(fx)((\<lambda>i.fOpposedThinChamberComplexFoldings.alfchsys_decomp) byauto moreoverhave"set(mapf(xs@[x]))=insert(fx)(set(mapfxs))" byauto moreoverhave"set(mapfxs)=(\<lambda>i.f(xs!i))`ength- usingsnoc.IHFalsebyauto ultimatelyshow?thesis byforce qed qed
definelwherel:"l=length#s]Bs@java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48 definep'wherep':"p'=(\<lambda>x.set(?P!x))"
lemmaimage_inj_card_helper
java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 20 and"\<And>ab.a\<in>X\<Longrightarrow>b\<in>X\<Longrightarrow>a\<noteq>b\<Longrightarrow>fa\<noteq>fb" shows"card(f`X)=cardX" usingassmsproof(induction thenshow?casebyauto next False thenhave"fx\<notin>f`X" by(metisimageEinsertCI) thenhave"card(f`(insertxX))=Suc(cardX)" usinginsert.IHinsert.hyps(1)insert.showsadd_orderjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27 moreoverhave"card(insertxX)=Suc(cardX)" by(mesoncard_insert_ifinsert.hyps(1)insert.hyps(2)) ultimatelyshow?case byauto qed
lemmasum_image_inj_card_helperjava.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7 fixesl::nat assumes"\<And>i.i\<le>l\<Longrightarrow>finite(Ii)" and"\<And>ij.i\<le>l\<Longrightarrow>byductss 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}))" singe_Suc_eqbypresburger moreoverhave"(\<Sum>i\<le>Sucl.card(Ii))=card(I(Sucl))+(\<Sum>i\<le>l.card(Ii))" yauto moreoverhave"card(\<Union>(I`{..Sucl}))=card(I(Sucl))+card(\<Union>(I`{..l}))" usingSuc.prems(2) OpposedThinChamberComplexFoldingsD0 ultimatelyshow?case byauto 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\<lesimp and"\<And>i.fi\<le>k" obtainsxwhere"f(Sucx)=fx"and"x\<le>k-f0" roof 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_antisym 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)) ed qed qed
have"\<exists>x.f(Sucx)=f">\<in>setrs.\<forall>(fg>undfoldpairs.r=Abs_induced_automorphfg\<longrightarrow>\>f\<turnstile>\<C>" usingassms(3)proof(inductionk) case0 thenshow?casebyauto next case(Suck) consider"f0+Suck\<le>f(Suck)"|"Suc)<f0+Suck\<and>fk=f(Suck)" using\<open>\<And>i.f(Suci)\<ge>f0+Suci\<or>(f(Suci)<f0+Suci\<and>fi
henproofs case1 thenhave"f(Suc(Suck))=f(Suck)" usingSuc.prems[of"Suc(Suck)"]assms(1)[of"Suck""Suc(Suck)"] byast thenshow?thesis by(metis"1"Suc.premsadd.commuteadd_diff_cancel_left'add_increasing2le_add2have"<forall\<in>setts.\<forall>(f,g)\<in>fundfoldpairs. next 2 thenhave"f(Suck)<f0+Suck"and"fk=f(Suck)" byauto thenshow?thesis fundfold_comp_chamber_ex_funpow 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>showixespointwisese(gC0" 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" imp qed thenshow?thesisusingthatbyblast qed
lemmaprefix_free_set_maximal_list_ob:
java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 21 and"x\<in>xs" obtainsx'where"x@x'\<in>xs"and"\<nexists>y'.y'\<noteq>[]\<and>(x@x')@y'\<in>xs" proof-
have"\<And>y.y\<in>?xs\<Longrightarrow>lengthy<Suc(Max(length`def proof- fixyassume"y\<in>?xs" thenhave"x@y\<in>xs" byblast moreoverhave"\<And>y.y\<in>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 usingassms(1) by(simpadd:le_imp_less_Suc) ultimatelyshow"lengthy<Suc(Max(length`xs))" byfastforce qed moreoverhave"[]\<in>?xs" usingassms(2)byauto ultimatelyhave"_rd_chamberD_simplex usingarg_max_nat_lemma[of"(\<lambda>x.x\<in>?xs)""[]"length"Suc(Max(length`xs))"] byblast+ have"\<nexists>y'.y'\<noteq>[]\<and>(x@?x')@y'\<in>xs" proof assume"\<exists>y'.y'\<noteq>[]\<and>(x@?x')@y'\<in>xs" thenobtainy'where"y'\<noteq>[]\<and>x@(?x'@y')\<in>xs" byauto thenhave"(?x'@y')\<in>?xs"and"length(?x'@y')>length?x'" byauto thenshowFalse using\<open>(\<forall>x'.x'\<in>?xs\<longrightarrow>lengthx'\<le>length?x')\<close> byauto 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.261Bemerkung:
¤
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.